Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Type as Trait>` path we resolve the trait name
name = [Path.super.getText(), Path.super.getSegment().getTraitTypeRepr().getPath().getText()]
}

override Path getQualifier() { result = Path.super.getQualifier() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
multipleResolvedTargets
| main.rs:126:9:126:11 | f(...) |
| main.rs:366:9:368:16 | ...::f(...) |
| main.rs:369:9:371:16 | ...::f(...) |
| main.rs:450:9:454:16 | ...::f(...) |
| main.rs:455:9:459:16 | ...::f(...) |
| main.rs:565:9:566:15 | ...::Assoc(...) |
| main.rs:568:9:569:12 | ...::f1(...) |
| main.rs:571:9:572:12 | ...::f1(...) |
| main.rs:566:9:567:15 | ...::Assoc(...) |
| main.rs:569:9:570:12 | ...::f1(...) |
| main.rs:572:9:573:12 | ...::f1(...) |
33 changes: 22 additions & 11 deletions rust/ql/test/library-tests/path-resolution/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod m8 {
<MyStruct as // $ item=I50
MyTrait // $ item=I47
> // $ 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
Expand Down Expand Up @@ -305,7 +305,7 @@ mod m13 {

mod m15 {
trait Trait1 {
fn f(&self);
fn f(&self); // Trait1::f

fn g(&self); // I80
} // I79
Expand All @@ -317,7 +317,7 @@ mod m15 {
println!("m15::Trait2::f"); // $ item=println
Self::g(self); // $ item=I80
self.g(); // $ item=I80
}
} // Trait2::f
} // I82

#[rustfmt::skip]
Expand Down Expand Up @@ -365,10 +365,10 @@ mod m15 {
let x = S; // $ item=I81
<S // $ item=I81
as Trait1 // $ item=I79
>::f(&x); // $ MISSING: item=I76
>::f(&x); // $ item=Trait1::f
<S // $ item=I81
as Trait2 // $ item=I82
>::f(&x); // $ MISSING: item=I78
>::f(&x); // $ item=Trait2::f
S::g(&x); // $ item=I77
x.g(); // $ item=I77
} // I75
Expand All @@ -379,10 +379,11 @@ mod m16 {
trait Trait1<
T // I84
> {
fn f(&self) -> T; // $ item=I84
fn f(&self) -> T // $ item=I84
; // Trait1::f

fn g(&self) -> T {// $ item=I84
self.f() // $ item=f
self.f() // $ item=Trait1::f
} // I85

fn h(&self) -> T { // $ item=I84
Expand All @@ -406,7 +407,7 @@ mod m16 {
Self::g(self); // $ item=I85
self.g(); // $ item=I85
Self::c // $ item=I94
}
} // Trait2::f
} // I89

struct S; // I90
Expand Down Expand Up @@ -451,12 +452,12 @@ mod m16 {
as Trait1<
S // $ item=I90
> // $ item=I86
>::f(&x); // $ MISSING: item=I91
>::f(&x); // $ item=Trait1::f
<S // $ item=I90
as Trait2<
S // $ item=I90
> // $ 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
Expand All @@ -466,7 +467,7 @@ mod m16 {
as Trait1<
S // $ item=I90
> // $ item=I86
>::c; // $ MISSING: item=I95
>::c; // $ item=I94
} // I83

trait Trait3 {
Expand Down Expand Up @@ -940,6 +941,16 @@ mod associated_types_subtrait {
self.0
}
}

#[rustfmt::skip]
impl S<bool> { // $ item=S item=bool
fn _test() {
let _c: <S<i32> as Super>::Out = 'a'; // $ item=S item=i32 item=Super item=SuperAssoc
let _i: <S<bool> as Super>::Out = 1; // $ item=S item=bool item=Super item=SuperAssoc

let _b: <S<bool> as SuperAlt>::Out = true; // $ item=S item=bool item=SuperAlt item=SuperAltAssoc
}
}
}

use std::{self as ztd}; // $ item=std
Expand Down
Loading