Skip to content

Commit 93e7202

Browse files
authored
Merge pull request #17940 from geoffw0/resolvable
Rust: Add unresolved macro calls diagnostic
2 parents 74aa47a + f92e855 commit 93e7202

12 files changed

+39
-12
lines changed

rust/ql/src/queries/diagnostics/UnextractedElements.ql

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @name Unextracted Elements
33
* @description List all elements that weren't extracted due to unimplemented features or parse errors.
4+
* @kind diagnostic
45
* @id rust/diagnostics/unextracted-elements
56
*/
67

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @name Unresolved Macro Calls
3+
* @description List all macro calls that were not resolved to a target.
4+
* @kind diagnostic
5+
* @id rust/diagnostics/unresolved-macro-calls
6+
*/
7+
8+
import rust
9+
10+
from MacroCall mc
11+
where not mc.hasExpanded()
12+
select mc, "Macro call was not resolved to a target."

rust/ql/src/queries/summary/SummaryStats.ql

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ where
3737
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
3838
or
3939
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
40-
select key, value
40+
or
41+
key = "Macro calls - total" and value = count(MacroCall mc)
42+
or
43+
key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded())
44+
or
45+
key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded())
46+
select key, value order by key

rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ extractionWarning
55
| does_not_compile.rs:2:21:2:20 | expected SEMICOLON |
66
| does_not_compile.rs:2:26:2:25 | expected SEMICOLON |
77
| error.rs:2:5:2:17 | An error! |
8+
| my_macro.rs:17:9:17:27 | macro expansion failed: could not resolve macro 'myUndefinedMacro' |

rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
| does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 |
55
| does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 |
66
| error.rs:2:5:2:17 | An error! | Extraction warning in error.rs with message An error! | 1 |
7+
| 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 |
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| 59 |
1+
| 60 |
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| 59 |
1+
| 60 |

rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| my_struct.rs:0:0:0:0 | my_struct.rs | 20 |
22
| comments.rs:0:0:0:0 | comments.rs | 13 |
33
| main.rs:0:0:0:0 | main.rs | 8 |
4-
| my_macro.rs:0:0:0:0 | my_macro.rs | 7 |
4+
| my_macro.rs:0:0:0:0 | my_macro.rs | 8 |
55
| lib.rs:0:0:0:0 | lib.rs | 5 |
66
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
77
| error.rs:0:0:0:0 | error.rs | 3 |
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
| Elements extracted | 375 |
1+
| Elements extracted | 382 |
22
| Elements unextracted | 0 |
33
| Extraction errors | 0 |
4-
| Extraction warnings | 6 |
4+
| Extraction warnings | 7 |
55
| Files extracted - total | 8 |
6-
| Files extracted - with errors | 2 |
7-
| Files extracted - without errors | 6 |
6+
| Files extracted - with errors | 3 |
7+
| Files extracted - without errors | 5 |
88
| Inconsistencies - AST | 0 |
99
| Inconsistencies - CFG | 0 |
1010
| Inconsistencies - data flow | 0 |
11-
| Lines of code extracted | 59 |
12-
| Lines of user code extracted | 59 |
11+
| Lines of code extracted | 60 |
12+
| Lines of user code extracted | 60 |
13+
| Macro calls - resolved | 8 |
14+
| Macro calls - total | 9 |
15+
| Macro calls - unresolved | 1 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| my_macro.rs:17:9:17:27 | myUndefinedMacro!... | Macro call was not resolved to a target. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/diagnostics/UnresolvedMacroCalls.ql

rust/ql/test/query-tests/diagnostics/my_macro.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* total lines in this file: 18
3-
* of which code: 10
2+
* total lines in this file: 19
3+
* of which code: 11
44
* of which only comments: 6
55
* of which blank: 2
66
*/
@@ -14,5 +14,6 @@ macro_rules! myMacro {
1414
pub fn my_func() {
1515
if true {
1616
myMacro!();
17+
myUndefinedMacro!();
1718
}
1819
}

0 commit comments

Comments
 (0)