Skip to content
Merged
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
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ abstract class ItemNode extends Locatable {
Stages::PathResolutionStage::ref() and
result = this.getASuccessorRec(name)
or
preludeEdge(this, name, result)
preludeEdge(this, name, result) and not declares(this, _, name)
or
name = "super" and
if this instanceof Module or this instanceof SourceFile
Expand Down
18 changes: 18 additions & 0 deletions rust/ql/test/library-tests/path-resolution/my.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ mod my4 {
}

pub use my4::my5::f as nested_f; // $ item=I201

type Result<
T, // T
> = ::std::result::Result<
T, // $ item=T
String,
>; // my::Result

fn int_div(
x: i32, //
y: i32,
) -> Result<i32> // $ item=my::Result
{
if y == 0 {
return Err("Div by zero".to_string());
}
Ok(x / y)
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ resolvePath
| my.rs:18:9:18:11 | my4 | my.rs:14:1:16:1 | mod my4 |
| my.rs:18:9:18:16 | ...::my5 | my.rs:15:5:15:16 | mod my5 |
| my.rs:18:9:18:19 | ...::f | my/my4/my5/mod.rs:1:1:3:1 | fn f |
| my.rs:22:5:22:9 | std | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/std/src/lib.rs:0:0:0:0 | Crate(std@0.0.0) |
| my.rs:22:5:22:17 | ...::result | file://:0:0:0:0 | mod result |
| my.rs:22:5:25:1 | ...::Result::<...> | file://:0:0:0:0 | enum Result |
| my.rs:23:5:23:5 | T | my.rs:21:5:21:5 | T |
| my.rs:30:6:30:16 | Result::<...> | my.rs:20:1:25:2 | type Result<...> |
| my.rs:33:16:33:18 | Err | file://:0:0:0:0 | Err |
| my.rs:35:5:35:6 | Ok | file://:0:0:0:0 | Ok |
| my/nested.rs:9:13:9:13 | f | my/nested.rs:3:9:5:9 | fn f |
| my/nested.rs:15:9:15:15 | nested2 | my/nested.rs:2:5:11:5 | mod nested2 |
| my/nested.rs:15:9:15:18 | ...::f | my/nested.rs:3:9:5:9 | fn f |
Expand Down
13 changes: 12 additions & 1 deletion rust/ql/test/library-tests/path-resolution/path-resolution.ql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import TestUtils

query predicate mod(Module m) { toBeTested(m) }

query predicate resolvePath(Path p, ItemNode i) {
class ItemNodeLoc extends Locatable instanceof ItemNode {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(string file |
super.getLocation().hasLocationInfo(file, startline, startcolumn, endline, endcolumn) and
filepath = file.regexpReplaceAll("^/.*/.rustup/toolchains/[^/]+/", "/RUSTUP_HOME/toolchain/")
)
}
}

query predicate resolvePath(Path p, ItemNodeLoc i) {
toBeTested(p) and not p.isInMacroExpansion() and i = resolvePath(p)
}