diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 7e77669cc4f..859135cd3b1 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -1556,7 +1556,8 @@ private class PathExtPath extends PathExt instanceof Path { tree.hasPath() and this = getAUseTreeUseTree(tree).getPath().getQualifier*() ) and - name = Path.super.getText() + // For a `` path we resolve the trait name + name = [Path.super.getText(), Path.super.getSegment().getTraitTypeRepr().getPath().getText()] } override Path getQualifier() { result = Path.super.getQualifier() } diff --git a/rust/ql/test/library-tests/path-resolution/main.rs b/rust/ql/test/library-tests/path-resolution/main.rs index 3276807cacb..38909e167fa 100644 --- a/rust/ql/test/library-tests/path-resolution/main.rs +++ b/rust/ql/test/library-tests/path-resolution/main.rs @@ -194,7 +194,7 @@ mod m8 { // $ MISSING: item=52 - ::f(&x); // $ MISSING: item=I53 + ::f(&x); // $ item=I48 let x = MyStruct {}; // $ item=I50 x.f(); // $ item=I53 let x = MyStruct {}; // $ item=I50 @@ -365,10 +365,10 @@ mod m15 { let x = S; // $ item=I81 ::f(&x); // $ MISSING: item=I76 + >::f(&x); // $ item=Trait1::f ::f(&x); // $ MISSING: item=I78 + >::f(&x); // $ item=Trait2::f S::g(&x); // $ item=I77 x.g(); // $ item=I77 } // I75 @@ -452,12 +452,12 @@ mod m16 { as Trait1< S // $ item=I90 > // $ item=I86 - >::f(&x); // $ MISSING: item=I91 + >::f(&x); // $ item=Trait1::f // $ item=I89 - >::f(&x); // $ MISSING: item=I93 + >::f(&x); // $ item=Trait2::f S::g(&x); // $ item=I92 x.g(); // $ item=I92 S::h(&x); // $ item=I96 @@ -467,7 +467,7 @@ mod m16 { as Trait1< S // $ item=I90 > // $ item=I86 - >::c; // $ MISSING: item=I95 + >::c; // $ item=I94 } // I83 trait Trait3 { @@ -945,10 +945,10 @@ mod associated_types_subtrait { #[rustfmt::skip] impl S { // $ item=S item=bool fn _test() { - let _c: as Super>::Out = 'a'; // $ item=S item=i32 item=Super MISSING: item=SuperAssoc - let _i: as Super>::Out = 1; // $ item=S item=bool item=Super MISSING: item=SuperAssoc + let _c: as Super>::Out = 'a'; // $ item=S item=i32 item=Super item=SuperAssoc + let _i: as Super>::Out = 1; // $ item=S item=bool item=Super item=SuperAssoc - let _b: as SuperAlt>::Out = true; // $ item=S item=bool item=SuperAlt MISSING: item=SuperAltAssoc + let _b: as SuperAlt>::Out = true; // $ item=S item=bool item=SuperAlt item=SuperAltAssoc } } } diff --git a/rust/ql/test/library-tests/path-resolution/path-resolution.expected b/rust/ql/test/library-tests/path-resolution/path-resolution.expected index 9b65bb84666..f04c0577b90 100644 --- a/rust/ql/test/library-tests/path-resolution/path-resolution.expected +++ b/rust/ql/test/library-tests/path-resolution/path-resolution.expected @@ -146,6 +146,8 @@ resolvePath | main.rs:192:9:192:18 | ...::f | main.rs:153:9:153:20 | fn f | | main.rs:193:9:193:16 | MyStruct | main.rs:162:5:162:22 | struct MyStruct | | main.rs:193:9:193:19 | ...::f | main.rs:169:33:174:9 | fn f | +| main.rs:194:9:196:9 | <...> | main.rs:152:5:160:5 | trait MyTrait | +| main.rs:194:9:197:11 | ...::f | main.rs:153:9:153:20 | fn f | | main.rs:194:10:194:17 | MyStruct | main.rs:162:5:162:22 | struct MyStruct | | main.rs:195:10:195:16 | MyTrait | main.rs:152:5:160:5 | trait MyTrait | | main.rs:198:17:198:24 | MyStruct | main.rs:162:5:162:22 | struct MyStruct | @@ -207,8 +209,12 @@ resolvePath | main.rs:358:13:358:19 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:364:9:364:15 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:365:17:365:17 | S | main.rs:338:5:338:13 | struct S | +| main.rs:366:9:368:9 | <...> | main.rs:307:5:311:5 | trait Trait1 | +| main.rs:366:9:368:12 | ...::f | main.rs:308:9:308:20 | fn f | | main.rs:366:10:366:10 | S | main.rs:338:5:338:13 | struct S | | main.rs:367:14:367:19 | Trait1 | main.rs:307:5:311:5 | trait Trait1 | +| main.rs:369:9:371:9 | <...> | main.rs:313:5:321:5 | trait Trait2 | +| main.rs:369:9:371:12 | ...::f | main.rs:315:18:320:9 | fn f | | main.rs:369:10:369:10 | S | main.rs:338:5:338:13 | struct S | | main.rs:370:14:370:19 | Trait2 | main.rs:313:5:321:5 | trait Trait2 | | main.rs:372:9:372:9 | S | main.rs:338:5:338:13 | struct S | @@ -251,9 +257,13 @@ resolvePath | main.rs:443:13:443:19 | ...::c | main.rs:431:9:432:9 | Const | | main.rs:449:9:449:15 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:450:17:450:17 | S | main.rs:413:5:413:13 | struct S | +| main.rs:451:9:455:9 | <...> | main.rs:378:5:396:5 | trait Trait1 | +| main.rs:451:9:455:12 | ...::f | main.rs:382:9:383:9 | fn f | | main.rs:451:10:451:10 | S | main.rs:413:5:413:13 | struct S | | main.rs:452:14:454:11 | Trait1::<...> | main.rs:378:5:396:5 | trait Trait1 | | main.rs:453:13:453:13 | S | main.rs:413:5:413:13 | struct S | +| main.rs:456:9:460:9 | <...> | main.rs:398:5:411:5 | trait Trait2 | +| main.rs:456:9:460:12 | ...::f | main.rs:404:13:410:9 | fn f | | main.rs:456:10:456:10 | S | main.rs:413:5:413:13 | struct S | | main.rs:457:14:459:11 | Trait2::<...> | main.rs:398:5:411:5 | trait Trait2 | | main.rs:458:13:458:13 | S | main.rs:413:5:413:13 | struct S | @@ -263,6 +273,8 @@ resolvePath | main.rs:463:9:463:12 | ...::h | main.rs:389:9:392:9 | fn h | | main.rs:465:9:465:9 | S | main.rs:413:5:413:13 | struct S | | main.rs:465:9:465:12 | ...::c | main.rs:431:9:432:9 | Const | +| main.rs:466:9:470:9 | <...> | main.rs:378:5:396:5 | trait Trait1 | +| main.rs:466:9:470:12 | ...::c | main.rs:394:9:395:9 | Const | | main.rs:466:10:466:10 | S | main.rs:413:5:413:13 | struct S | | main.rs:467:14:469:11 | Trait1::<...> | main.rs:378:5:396:5 | trait Trait1 | | main.rs:468:13:468:13 | S | main.rs:413:5:413:13 | struct S | @@ -489,12 +501,18 @@ resolvePath | main.rs:940:23:940:31 | ...::Out | main.rs:923:9:923:17 | type Out | | main.rs:946:10:946:16 | S::<...> | main.rs:892:5:894:6 | struct S | | main.rs:946:12:946:15 | bool | {EXTERNAL LOCATION} | struct bool | +| main.rs:948:21:948:37 | <...> | main.rs:882:5:884:5 | trait Super | +| main.rs:948:21:948:42 | ...::Out | main.rs:883:9:883:17 | type Out | | main.rs:948:22:948:27 | S::<...> | main.rs:892:5:894:6 | struct S | | main.rs:948:24:948:26 | i32 | {EXTERNAL LOCATION} | struct i32 | | main.rs:948:32:948:36 | Super | main.rs:882:5:884:5 | trait Super | +| main.rs:949:21:949:38 | <...> | main.rs:882:5:884:5 | trait Super | +| main.rs:949:21:949:43 | ...::Out | main.rs:883:9:883:17 | type Out | | main.rs:949:22:949:28 | S::<...> | main.rs:892:5:894:6 | struct S | | main.rs:949:24:949:27 | bool | {EXTERNAL LOCATION} | struct bool | | main.rs:949:33:949:37 | Super | main.rs:882:5:884:5 | trait Super | +| main.rs:951:21:951:41 | <...> | main.rs:922:5:924:5 | trait SuperAlt | +| main.rs:951:21:951:46 | ...::Out | main.rs:923:9:923:17 | type Out | | main.rs:951:22:951:28 | S::<...> | main.rs:892:5:894:6 | struct S | | main.rs:951:24:951:27 | bool | {EXTERNAL LOCATION} | struct bool | | main.rs:951:33:951:40 | SuperAlt | main.rs:922:5:924:5 | trait SuperAlt | diff --git a/rust/ql/test/library-tests/type-inference/main.rs b/rust/ql/test/library-tests/type-inference/main.rs index 8f2002117da..b4f9b04f56f 100644 --- a/rust/ql/test/library-tests/type-inference/main.rs +++ b/rust/ql/test/library-tests/type-inference/main.rs @@ -205,10 +205,10 @@ mod method_call_trait_path_disambig { let s = S; let _b1 = FirstTrait::method(&s); // $ type=_b1:bool target=FirstTrait::method - let _b2 = ::method(&s); // $ type=_b2:bool target=FirstTrait::method SPURIOUS: target=SecondTrait::method + let _b2 = ::method(&s); // $ type=_b2:bool target=FirstTrait::method let _n1 = SecondTrait::method(&s); // $ type=_n1:i64 target=SecondTrait::method - let _n2 = ::method(&s); // $ type=_n2:i64 target=SecondTrait::method SPURIOUS: target=FirstTrait::method + let _n2 = ::method(&s); // $ type=_n2:i64 target=SecondTrait::method } } diff --git a/rust/ql/test/library-tests/type-inference/type-inference.expected b/rust/ql/test/library-tests/type-inference/type-inference.expected index 3d14c16902e..19e46b1cae6 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -1151,10 +1151,14 @@ inferCertainType | main.rs:207:13:207:15 | _b1 | | {EXTERNAL LOCATION} | bool | | main.rs:207:19:207:40 | ...::method(...) | | {EXTERNAL LOCATION} | bool | | main.rs:207:38:207:39 | &s | | {EXTERNAL LOCATION} | & | +| main.rs:208:13:208:15 | _b2 | | {EXTERNAL LOCATION} | bool | +| main.rs:208:19:208:47 | ...::method(...) | | {EXTERNAL LOCATION} | bool | | main.rs:208:45:208:46 | &s | | {EXTERNAL LOCATION} | & | | main.rs:210:13:210:15 | _n1 | | {EXTERNAL LOCATION} | i64 | | main.rs:210:19:210:41 | ...::method(...) | | {EXTERNAL LOCATION} | i64 | | main.rs:210:39:210:40 | &s | | {EXTERNAL LOCATION} | & | +| main.rs:211:13:211:15 | _n2 | | {EXTERNAL LOCATION} | i64 | +| main.rs:211:19:211:48 | ...::method(...) | | {EXTERNAL LOCATION} | i64 | | main.rs:211:46:211:47 | &s | | {EXTERNAL LOCATION} | & | | main.rs:228:15:228:18 | SelfParam | | main.rs:216:5:219:5 | MyThing | | main.rs:228:15:228:18 | SelfParam | A | main.rs:221:5:222:14 | S1 | @@ -6895,9 +6899,7 @@ inferType | main.rs:207:38:207:39 | &s | TRef | main.rs:200:5:200:13 | S | | main.rs:207:39:207:39 | s | | main.rs:200:5:200:13 | S | | main.rs:208:13:208:15 | _b2 | | {EXTERNAL LOCATION} | bool | -| main.rs:208:13:208:15 | _b2 | | {EXTERNAL LOCATION} | i64 | | main.rs:208:19:208:47 | ...::method(...) | | {EXTERNAL LOCATION} | bool | -| main.rs:208:19:208:47 | ...::method(...) | | {EXTERNAL LOCATION} | i64 | | main.rs:208:45:208:46 | &s | | {EXTERNAL LOCATION} | & | | main.rs:208:45:208:46 | &s | TRef | main.rs:200:5:200:13 | S | | main.rs:208:46:208:46 | s | | main.rs:200:5:200:13 | S | @@ -6906,9 +6908,7 @@ inferType | main.rs:210:39:210:40 | &s | | {EXTERNAL LOCATION} | & | | main.rs:210:39:210:40 | &s | TRef | main.rs:200:5:200:13 | S | | main.rs:210:40:210:40 | s | | main.rs:200:5:200:13 | S | -| main.rs:211:13:211:15 | _n2 | | {EXTERNAL LOCATION} | bool | | main.rs:211:13:211:15 | _n2 | | {EXTERNAL LOCATION} | i64 | -| main.rs:211:19:211:48 | ...::method(...) | | {EXTERNAL LOCATION} | bool | | main.rs:211:19:211:48 | ...::method(...) | | {EXTERNAL LOCATION} | i64 | | main.rs:211:46:211:47 | &s | | {EXTERNAL LOCATION} | & | | main.rs:211:46:211:47 | &s | TRef | main.rs:200:5:200:13 | S |