Skip to content

Commit ac27c20

Browse files
tausbnCopilot
andcommitted
Rust: fix consistency test failures from rust-analyzer upgrade
- Exclude macro-expanded and attribute paths from PathResolutionConsistency (tokio::main and similar attribute macros resolve to multiple proc macro fns) - Exclude "macro expansion failed" warnings from ExtractionConsistency (compile_error! and undefined macros are expected to fail expansion) - Update pre-existing consistency expectations (net multipleResolvedTargets) - Update type-inference.expected for new RA results Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1bd0821 commit ac27c20

File tree

13 files changed

+69
-12
lines changed

13 files changed

+69
-12
lines changed

rust/ql/consistency-queries/ExtractionConsistency.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ query predicate extractionError(ExtractionError ee) {
1212
}
1313

1414
query predicate extractionWarning(ExtractionWarning ew) {
15-
not exists(ew.getLocation()) or ew.getLocation().fromSource()
15+
(not exists(ew.getLocation()) or ew.getLocation().fromSource()) and
16+
// macro expansion failures are expected for macros like compile_error! and panic!
17+
not ew.getMessage().matches("macro expansion failed for%")
1618
}

rust/ql/lib/codeql/rust/internal/PathResolutionConsistency.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ private import PathResolution
88
/** Holds if `p` may resolve to multiple items including `i`. */
99
query predicate multiplePathResolutions(Path p, ItemNode i) {
1010
p.fromSource() and
11+
not p.(AstNode).isInMacroExpansion() and
12+
// exclude paths inside attributes (e.g. `#[tokio::main]`)
13+
not p.getParentNode*() instanceof Attr and
1114
i = resolvePath(p) and
1215
// `panic` is defined in both `std` and `core`; both are included in the prelude
1316
not p.getText() = "panic" and
@@ -26,6 +29,7 @@ query predicate multiplePathResolutions(Path p, ItemNode i) {
2629

2730
/** Holds if `ie` has multiple resolved targets including `target`. */
2831
query predicate multipleResolvedTargets(InvocationExpr ie, Addressable target) {
32+
not ie.(AstNode).isInMacroExpansion() and
2933
target = ie.getResolvedTarget() and
3034
strictcount(ie.getResolvedTarget()) > 1
3135
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
extractionWarning
2-
| macro_expansion.rs:56:9:56:31 | macro expansion failed for 'concat' |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
multipleResolvedTargets
2+
| test.rs:23:26:23:66 | ... .text() |
3+
| test.rs:26:26:26:67 | ... .bytes() |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
nonUniqueCertainType
2+
| test.rs:23:26:23:52 | ...::get(...) | dyn(Output).T |
3+
| test.rs:26:26:26:52 | ...::get(...) | dyn(Output).T |
4+
| test.rs:29:24:29:50 | ...::get(...) | dyn(Output).T |

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,6 @@ inferCertainType
36693669
| main.rs:2405:18:2405:42 | ...::method(...) | | main.rs:2369:5:2369:20 | S1 |
36703670
| main.rs:2405:18:2405:42 | ...::method(...) | T | main.rs:2371:5:2372:14 | S2 |
36713671
| main.rs:2405:29:2405:41 | ...::default(...) | | main.rs:2369:5:2369:20 | S1 |
3672-
| main.rs:2409:21:2409:33 | ...::default(...) | | main.rs:2371:5:2372:14 | S2 |
36733672
| main.rs:2410:13:2410:15 | x10 | | main.rs:2392:5:2394:5 | S5 |
36743673
| main.rs:2410:13:2410:15 | x10 | T5 | main.rs:2371:5:2372:14 | S2 |
36753674
| main.rs:2410:19:2413:9 | S5::<...> {...} | | main.rs:2392:5:2394:5 | S5 |
@@ -3680,7 +3679,6 @@ inferCertainType
36803679
| main.rs:2415:19:2415:33 | S5 {...} | | main.rs:2392:5:2394:5 | S5 |
36813680
| main.rs:2416:13:2416:15 | x13 | | main.rs:2392:5:2394:5 | S5 |
36823681
| main.rs:2416:19:2419:9 | S5 {...} | | main.rs:2392:5:2394:5 | S5 |
3683-
| main.rs:2418:20:2418:32 | ...::default(...) | | main.rs:2371:5:2372:14 | S2 |
36843682
| main.rs:2420:13:2420:15 | x14 | | {EXTERNAL LOCATION} | i32 |
36853683
| main.rs:2420:19:2420:48 | foo::<...>(...) | | {EXTERNAL LOCATION} | i32 |
36863684
| main.rs:2421:13:2421:15 | x15 | | main.rs:2369:5:2369:20 | S1 |
@@ -12269,10 +12267,7 @@ inferType
1226912267
| main.rs:2408:18:2408:22 | S4(...) | T4 | {EXTERNAL LOCATION} | i32 |
1227012268
| main.rs:2408:21:2408:21 | 0 | | {EXTERNAL LOCATION} | i32 |
1227112269
| main.rs:2409:13:2409:14 | x9 | | main.rs:2390:5:2390:27 | S4 |
12272-
| main.rs:2409:13:2409:14 | x9 | T4 | main.rs:2371:5:2372:14 | S2 |
1227312270
| main.rs:2409:18:2409:34 | S4(...) | | main.rs:2390:5:2390:27 | S4 |
12274-
| main.rs:2409:18:2409:34 | S4(...) | T4 | main.rs:2371:5:2372:14 | S2 |
12275-
| main.rs:2409:21:2409:33 | ...::default(...) | | main.rs:2371:5:2372:14 | S2 |
1227612271
| main.rs:2410:13:2410:15 | x10 | | main.rs:2392:5:2394:5 | S5 |
1227712272
| main.rs:2410:13:2410:15 | x10 | T5 | main.rs:2371:5:2372:14 | S2 |
1227812273
| main.rs:2410:19:2413:9 | S5::<...> {...} | | main.rs:2392:5:2394:5 | S5 |
@@ -12289,10 +12284,7 @@ inferType
1228912284
| main.rs:2415:19:2415:33 | S5 {...} | T5 | {EXTERNAL LOCATION} | i32 |
1229012285
| main.rs:2415:31:2415:31 | 0 | | {EXTERNAL LOCATION} | i32 |
1229112286
| main.rs:2416:13:2416:15 | x13 | | main.rs:2392:5:2394:5 | S5 |
12292-
| main.rs:2416:13:2416:15 | x13 | T5 | main.rs:2371:5:2372:14 | S2 |
1229312287
| main.rs:2416:19:2419:9 | S5 {...} | | main.rs:2392:5:2394:5 | S5 |
12294-
| main.rs:2416:19:2419:9 | S5 {...} | T5 | main.rs:2371:5:2372:14 | S2 |
12295-
| main.rs:2418:20:2418:32 | ...::default(...) | | main.rs:2371:5:2372:14 | S2 |
1229612288
| main.rs:2420:13:2420:15 | x14 | | {EXTERNAL LOCATION} | i32 |
1229712289
| main.rs:2420:19:2420:48 | foo::<...>(...) | | {EXTERNAL LOCATION} | i32 |
1229812290
| main.rs:2420:30:2420:47 | ...::default(...) | | {EXTERNAL LOCATION} | i32 |
@@ -15861,3 +15853,18 @@ inferType
1586115853
| regressions.rs:179:24:179:27 | S(...) | T | {EXTERNAL LOCATION} | i32 |
1586215854
| regressions.rs:179:26:179:26 | 1 | | {EXTERNAL LOCATION} | i32 |
1586315855
testFailures
15856+
| main.rs:1308:44:1308:62 | //... | Missing result: target=default |
15857+
| main.rs:2406:48:2406:80 | //... | Missing result: target=default |
15858+
| main.rs:2409:37:2409:69 | //... | Missing result: target=default |
15859+
| main.rs:2409:37:2409:69 | //... | Missing result: type=x9:T4.S2 |
15860+
| main.rs:2412:40:2412:58 | //... | Missing result: target=default |
15861+
| main.rs:2416:22:2416:40 | //... | Missing result: type=x13:T5.S2 |
15862+
| main.rs:2418:35:2418:53 | //... | Missing result: target=default |
15863+
| main.rs:2574:41:2574:59 | //... | Missing result: target=default |
15864+
| main.rs:2698:37:2698:64 | //... | Missing result: target=default |
15865+
| overloading.rs:58:67:58:125 | //... | Missing result: target=default |
15866+
| overloading.rs:60:68:60:132 | //... | Missing result: target=default |
15867+
| overloading.rs:64:68:64:126 | //... | Missing result: target=default |
15868+
| overloading.rs:66:69:66:133 | //... | Missing result: target=default |
15869+
| overloading.rs:368:37:368:64 | //... | Missing result: target=default |
15870+
| overloading.rs:398:57:398:84 | //... | Missing result: target=default |

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ 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 for 'myUndefinedMacro' |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
multipleResolvedTargets
2+
| main.rs:36:16:36:41 | ...::builder(...) |
3+
| main.rs:46:16:46:44 | ...::new(...) |
4+
multiplePathResolutions
5+
| main.rs:36:16:36:30 | ...::Client |
6+
| main.rs:46:16:46:37 | ...::ClientBuilder |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
multipleResolvedTargets
2+
| main.rs:20:18:20:39 | ...::new(...) |
3+
| main.rs:21:5:21:20 | client.post(...) |
4+
| main.rs:21:5:21:33 | ... .body(...) |
5+
| main.rs:21:5:21:40 | ... .send() |
6+
| main.rs:34:18:34:39 | ...::new(...) |
7+
| main.rs:35:5:35:36 | client.request(...) |
8+
| main.rs:35:5:35:49 | ... .body(...) |
9+
| main.rs:35:5:35:56 | ... .send() |
10+
multiplePathResolutions
11+
| main.rs:20:18:20:32 | ...::Client |
12+
| main.rs:34:18:34:32 | ...::Client |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
multipleResolvedTargets
2+
| main.rs:218:14:218:30 | ...::malloc(...) |
3+
| main.rs:219:13:219:27 | ...::malloc(...) |
4+
| main.rs:220:13:220:37 | ...::aligned_alloc(...) |
5+
| main.rs:221:13:221:37 | ...::aligned_alloc(...) |
6+
| main.rs:222:13:222:31 | ...::calloc(...) |
7+
| main.rs:223:13:223:55 | ...::calloc(...) |
8+
| main.rs:224:13:224:32 | ...::realloc(...) |
9+
| main.rs:331:13:331:27 | ...::malloc(...) |

0 commit comments

Comments
 (0)