diff --git a/rust/ql/src/queries/diagnostics/UnextractedElements.ql b/rust/ql/src/queries/diagnostics/UnextractedElements.ql index dccf7d2ab09f..1a819e3f7847 100644 --- a/rust/ql/src/queries/diagnostics/UnextractedElements.ql +++ b/rust/ql/src/queries/diagnostics/UnextractedElements.ql @@ -1,6 +1,7 @@ /** * @name Unextracted Elements * @description List all elements that weren't extracted due to unimplemented features or parse errors. + * @kind diagnostic * @id rust/diagnostics/unextracted-elements */ diff --git a/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql new file mode 100644 index 000000000000..a20c5035b6ab --- /dev/null +++ b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql @@ -0,0 +1,12 @@ +/** + * @name Unresolved Macro Calls + * @description List all macro calls that were not resolved to a target. + * @kind diagnostic + * @id rust/diagnostics/unresolved-macro-calls + */ + +import rust + +from MacroCall mc +where not mc.hasExpanded() +select mc, "Macro call was not resolved to a target." diff --git a/rust/ql/src/queries/summary/SummaryStats.ql b/rust/ql/src/queries/summary/SummaryStats.ql index 3f24eb50d196..72a876ba08ca 100644 --- a/rust/ql/src/queries/summary/SummaryStats.ql +++ b/rust/ql/src/queries/summary/SummaryStats.ql @@ -37,4 +37,10 @@ where key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies() or key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies() -select key, value + or + key = "Macro calls - total" and value = count(MacroCall mc) + or + key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded()) + or + key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded()) +select key, value order by key diff --git a/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected b/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected index 5b4796faa8c5..f1c469a407da 100644 --- a/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected +++ b/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected @@ -5,3 +5,4 @@ extractionWarning | does_not_compile.rs:2:21:2:20 | expected SEMICOLON | | does_not_compile.rs:2:26:2:25 | expected SEMICOLON | | error.rs:2:5:2:17 | An error! | +| my_macro.rs:17:9:17:27 | macro expansion failed: could not resolve macro 'myUndefinedMacro' | diff --git a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected index 5ea7e808176e..7f14093f20e5 100644 --- a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected +++ b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected @@ -4,3 +4,4 @@ | does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | | does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | | error.rs:2:5:2:17 | An error! | Extraction warning in error.rs with message An error! | 1 | +| my_macro.rs:17:9:17:27 | macro expansion failed: could not resolve macro 'myUndefinedMacro' | Extraction warning in my_macro.rs with message macro expansion failed: could not resolve macro 'myUndefinedMacro' | 1 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index 6facd293859d..5fa7b20e01bb 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 59 | +| 60 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 6facd293859d..5fa7b20e01bb 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 59 | +| 60 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index b34654710961..0a58a05feed2 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,7 +1,7 @@ | my_struct.rs:0:0:0:0 | my_struct.rs | 20 | | comments.rs:0:0:0:0 | comments.rs | 13 | | main.rs:0:0:0:0 | main.rs | 8 | -| my_macro.rs:0:0:0:0 | my_macro.rs | 7 | +| my_macro.rs:0:0:0:0 | my_macro.rs | 8 | | lib.rs:0:0:0:0 | lib.rs | 5 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index a1ece2b1fd7b..a3cf68f9b878 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,12 +1,15 @@ -| Elements extracted | 375 | +| Elements extracted | 382 | | Elements unextracted | 0 | | Extraction errors | 0 | -| Extraction warnings | 6 | +| Extraction warnings | 7 | | Files extracted - total | 8 | -| Files extracted - with errors | 2 | -| Files extracted - without errors | 6 | +| Files extracted - with errors | 3 | +| Files extracted - without errors | 5 | | Inconsistencies - AST | 0 | | Inconsistencies - CFG | 0 | | Inconsistencies - data flow | 0 | -| Lines of code extracted | 59 | -| Lines of user code extracted | 59 | +| Lines of code extracted | 60 | +| Lines of user code extracted | 60 | +| Macro calls - resolved | 8 | +| Macro calls - total | 9 | +| Macro calls - unresolved | 1 | diff --git a/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected new file mode 100644 index 000000000000..72f78794ab29 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected @@ -0,0 +1 @@ +| my_macro.rs:17:9:17:27 | myUndefinedMacro!... | Macro call was not resolved to a target. | diff --git a/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref new file mode 100644 index 000000000000..77f337e27032 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref @@ -0,0 +1 @@ +queries/diagnostics/UnresolvedMacroCalls.ql diff --git a/rust/ql/test/query-tests/diagnostics/my_macro.rs b/rust/ql/test/query-tests/diagnostics/my_macro.rs index d8a0cc2812bd..3b24857aa6c8 100644 --- a/rust/ql/test/query-tests/diagnostics/my_macro.rs +++ b/rust/ql/test/query-tests/diagnostics/my_macro.rs @@ -1,6 +1,6 @@ /** - * total lines in this file: 18 - * of which code: 10 + * total lines in this file: 19 + * of which code: 11 * of which only comments: 6 * of which blank: 2 */ @@ -14,5 +14,6 @@ macro_rules! myMacro { pub fn my_func() { if true { myMacro!(); + myUndefinedMacro!(); } }