Skip to content

Commit 9c483cd

Browse files
committed
Rust: Account for disambiguation in path resolution tests
1 parent 6fbf727 commit 9c483cd

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ private module ResolveTest implements TestSig {
4646
element = n.toString() and
4747
tag = "item"
4848
|
49-
item(resolvePath(n), value)
50-
or
51-
item(n.(MethodCallExpr).getStaticTarget(), value)
49+
exists(ItemNode i | item(i, value) |
50+
i = resolvePath(n) and
51+
not n = any(CallExpr ce).getFunction().(PathExpr).getPath()
52+
or
53+
exists(CallExpr ce |
54+
n = ce.getFunction().(PathExpr).getPath() and
55+
i = ce.getResolvedTarget()
56+
)
57+
or
58+
i = n.(MethodCallExpr).getStaticTarget()
59+
)
5260
)
5361
}
5462
}

rust/ql/test/library-tests/path-resolution/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ mod m8 {
189189
#[rustfmt::skip]
190190
pub fn g() {
191191
let x = MyStruct {}; // $ item=I50
192-
MyTrait::f(&x); // $ item=I48
192+
MyTrait::f(&x); // $ item=I53
193193
MyStruct::f(&x); // $ item=I53
194194
<MyStruct as // $ item=I50
195195
MyTrait // $ item=I47
196196
> // $ MISSING: item=52
197-
::f(&x); // $ MISSING: item=I53
197+
::f(&x); // $ item=I53
198198
let x = MyStruct {}; // $ item=I50
199199
x.f(); // $ item=I53
200200
let x = MyStruct {}; // $ item=I50
@@ -365,10 +365,10 @@ mod m15 {
365365
let x = S; // $ item=I81
366366
<S // $ item=I81
367367
as Trait1 // $ item=I79
368-
>::f(&x); // $ MISSING: item=I76
368+
>::f(&x); // $ item=I76 $ SPURIOUS item=I78
369369
<S // $ item=I81
370370
as Trait2 // $ item=I82
371-
>::f(&x); // $ MISSING: item=I78
371+
>::f(&x); // $ item=I78 $ SPURIOUS item=I76
372372
S::g(&x); // $ item=I77
373373
x.g(); // $ item=I77
374374
} // I75
@@ -386,7 +386,7 @@ mod m16 {
386386
} // I85
387387

388388
fn h(&self) -> T { // $ item=I84
389-
Self::g(&self); // $ item=I85
389+
Self::g(&self); // $ MISSING: item=I85
390390
self.g() // $ item=I85
391391
} // I96
392392

@@ -451,12 +451,12 @@ mod m16 {
451451
as Trait1<
452452
S // $ item=I90
453453
> // $ item=I86
454-
>::f(&x); // $ MISSING: item=I91
454+
>::f(&x); // $ item=I91 $ SPURIOUS: item=I93
455455
<S // $ item=I90
456456
as Trait2<
457457
S // $ item=I90
458458
> // $ item=I89
459-
>::f(&x); // $ MISSING: item=I93
459+
>::f(&x); // $ item=I93 $ SPURIOUS: item=I91
460460
S::g(&x); // $ item=I92
461461
x.g(); // $ item=I92
462462
S::h(&x); // $ item=I96
@@ -627,7 +627,7 @@ mod trait_visibility {
627627
{
628628
// The `Bar` trait is not visible, but we can refer to its method
629629
// with a full path.
630-
m::Bar::a_method(&x); // $ item=Bar::a_method
630+
m::Bar::a_method(&x); // $ item=X_Bar::a_method
631631
}
632632
} // trait_visibility::f
633633
}

rust/ql/test/library-tests/path-resolution/path-resolution.expected

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ resolvePath
143143
| main.rs:185:13:185:13 | f | main.rs:164:5:166:5 | fn f |
144144
| main.rs:191:17:191:24 | MyStruct | main.rs:162:5:162:22 | struct MyStruct |
145145
| main.rs:192:9:192:15 | MyTrait | main.rs:152:5:160:5 | trait MyTrait |
146-
| main.rs:192:9:192:18 | ...::f | main.rs:153:9:153:20 | fn f |
146+
| main.rs:192:9:192:18 | ...::f | main.rs:169:33:174:9 | fn f |
147147
| main.rs:193:9:193:16 | MyStruct | main.rs:162:5:162:22 | struct MyStruct |
148148
| main.rs:193:9:193:19 | ...::f | main.rs:169:33:174:9 | fn f |
149+
| main.rs:194:9:197:11 | ...::f | main.rs:169:33:174:9 | fn f |
149150
| main.rs:194:10:194:17 | MyStruct | main.rs:162:5:162:22 | struct MyStruct |
150151
| main.rs:195:10:195:16 | MyTrait | main.rs:152:5:160:5 | trait MyTrait |
151152
| main.rs:198:17:198:24 | MyStruct | main.rs:162:5:162:22 | struct MyStruct |
@@ -207,8 +208,12 @@ resolvePath
207208
| main.rs:358:13:358:19 | println | {EXTERNAL LOCATION} | MacroRules |
208209
| main.rs:364:9:364:15 | println | {EXTERNAL LOCATION} | MacroRules |
209210
| main.rs:365:17:365:17 | S | main.rs:338:5:338:13 | struct S |
211+
| main.rs:366:9:368:12 | ...::f | main.rs:342:15:347:9 | fn f |
212+
| main.rs:366:9:368:12 | ...::f | main.rs:356:15:359:9 | fn f |
210213
| main.rs:366:10:366:10 | S | main.rs:338:5:338:13 | struct S |
211214
| main.rs:367:14:367:19 | Trait1 | main.rs:307:5:311:5 | trait Trait1 |
215+
| main.rs:369:9:371:12 | ...::f | main.rs:342:15:347:9 | fn f |
216+
| main.rs:369:9:371:12 | ...::f | main.rs:356:15:359:9 | fn f |
212217
| main.rs:369:10:369:10 | S | main.rs:338:5:338:13 | struct S |
213218
| main.rs:370:14:370:19 | Trait2 | main.rs:313:5:321:5 | trait Trait2 |
214219
| main.rs:372:9:372:9 | S | main.rs:338:5:338:13 | struct S |
@@ -217,7 +222,6 @@ resolvePath
217222
| main.rs:384:24:384:24 | T | main.rs:380:7:380:7 | T |
218223
| main.rs:388:24:388:24 | T | main.rs:380:7:380:7 | T |
219224
| main.rs:389:13:389:16 | Self | main.rs:378:5:395:5 | trait Trait1 |
220-
| main.rs:389:13:389:19 | ...::g | main.rs:384:9:386:9 | fn g |
221225
| main.rs:393:18:393:18 | T | main.rs:380:7:380:7 | T |
222226
| main.rs:401:9:403:9 | Trait1::<...> | main.rs:378:5:395:5 | trait Trait1 |
223227
| main.rs:402:11:402:11 | T | main.rs:399:7:399:7 | T |
@@ -251,9 +255,13 @@ resolvePath
251255
| main.rs:442:13:442:19 | ...::c | main.rs:430:9:431:9 | Const |
252256
| main.rs:448:9:448:15 | println | {EXTERNAL LOCATION} | MacroRules |
253257
| main.rs:449:17:449:17 | S | main.rs:412:5:412:13 | struct S |
258+
| main.rs:450:9:454:12 | ...::f | main.rs:418:15:423:9 | fn f |
259+
| main.rs:450:9:454:12 | ...::f | main.rs:438:15:443:9 | fn f |
254260
| main.rs:450:10:450:10 | S | main.rs:412:5:412:13 | struct S |
255261
| main.rs:451:14:453:11 | Trait1::<...> | main.rs:378:5:395:5 | trait Trait1 |
256262
| main.rs:452:13:452:13 | S | main.rs:412:5:412:13 | struct S |
263+
| main.rs:455:9:459:12 | ...::f | main.rs:418:15:423:9 | fn f |
264+
| main.rs:455:9:459:12 | ...::f | main.rs:438:15:443:9 | fn f |
257265
| main.rs:455:10:455:10 | S | main.rs:412:5:412:13 | struct S |
258266
| main.rs:456:14:458:11 | Trait2::<...> | main.rs:397:5:410:5 | trait Trait2 |
259267
| main.rs:457:13:457:13 | S | main.rs:412:5:412:13 | struct S |
@@ -350,7 +358,7 @@ resolvePath
350358
| main.rs:625:13:625:23 | ...::a_method | main.rs:594:26:597:13 | fn a_method |
351359
| main.rs:630:13:630:13 | m | main.rs:577:5:599:5 | mod m |
352360
| main.rs:630:13:630:18 | ...::Bar | main.rs:582:9:584:9 | trait Bar |
353-
| main.rs:630:13:630:28 | ...::a_method | main.rs:583:13:583:31 | fn a_method |
361+
| main.rs:630:13:630:28 | ...::a_method | main.rs:594:26:597:13 | fn a_method |
354362
| main.rs:643:10:643:16 | MyTrait | main.rs:636:5:638:5 | trait MyTrait |
355363
| main.rs:644:9:644:9 | S | main.rs:640:5:640:13 | struct S |
356364
| main.rs:646:13:646:19 | println | {EXTERNAL LOCATION} | MacroRules |

rust/ql/test/library-tests/path-resolution/path-resolution.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ query predicate mod(Module m) { toBeTested(m) }
88
query predicate resolvePath(PathExt p, ItemNode i) {
99
toBeTested(p) and
1010
not p.isFromMacroExpansion() and
11-
i = resolvePath(p)
11+
(
12+
i = resolvePath(p) and
13+
not p = any(CallExpr ce).getFunction().(PathExpr).getPath()
14+
or
15+
exists(CallExpr ce |
16+
p = ce.getFunction().(PathExpr).getPath() and
17+
i = ce.getResolvedTarget()
18+
)
19+
)
1220
}

0 commit comments

Comments
 (0)