rustDeclaredExpressionMacros: the macros the file declares with `macro_rules!` whose arguments are Rust code by their own rules (#3484). Every rule of every declaration of the name must bind its arguments only as `expr`, `literal`, `block` or `stmt` fragments, or as `tt` fragments it writes back as code (never drops, nor hands to another macro). The declarations are found by their keyword in the t
(root: Node, src: &str)
| 2103 | /// writes back as code (never drops, nor hands to another macro). The |
| 2104 | /// declarations are found by their keyword in the text. |
| 2105 | fn rust_declared_expression_macros(root: Node, src: &str) -> HashSet<String> { |
| 2106 | let mut verdict: HashMap<&str, bool> = HashMap::new(); |
| 2107 | for (at, _) in src.match_indices("macro_rules!") { |
| 2108 | let Some(keyword) = root.descendant_for_byte_range(at, at + 1) else { continue }; |
| 2109 | if keyword.kind() != "macro_rules!" { |
| 2110 | continue; |
| 2111 | } |
| 2112 | let Some(def) = keyword.parent() else { continue }; |
| 2113 | if def.kind() != "macro_definition" { |
| 2114 | continue; |
| 2115 | } |
| 2116 | let Some(name_node) = def.child_by_field_name("name") else { continue }; |
| 2117 | let name = macro_tok_text(name_node, src); |
| 2118 | let ok = verdict.get(name) != Some(&false) && macro_declares_code_arguments(def, src); |
| 2119 | verdict.insert(name, ok); |
| 2120 | } |
| 2121 | verdict.into_iter().filter(|(_, ok)| *ok).map(|(name, _)| name.to_string()).collect() |
| 2122 | } |
| 2123 | |
| 2124 | /// declaresCodeArguments: whether every rule of a `macro_definition` takes Rust code. |
| 2125 | fn macro_declares_code_arguments(def: Node, src: &str) -> bool { |
no test coverage detected