diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 91d7e87704c6..bc9da4906ea0 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -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 diff --git a/rust/ql/test/library-tests/path-resolution/my.rs b/rust/ql/test/library-tests/path-resolution/my.rs index 2dcb1c76aebc..8a94c169f6fe 100644 --- a/rust/ql/test/library-tests/path-resolution/my.rs +++ b/rust/ql/test/library-tests/path-resolution/my.rs @@ -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 // $ item=my::Result +{ + if y == 0 { + return Err("Div by zero".to_string()); + } + Ok(x / y) +} 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 1d480f2f5ad9..c52ea0980043 100644 --- a/rust/ql/test/library-tests/path-resolution/path-resolution.expected +++ b/rust/ql/test/library-tests/path-resolution/path-resolution.expected @@ -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 | diff --git a/rust/ql/test/library-tests/path-resolution/path-resolution.ql b/rust/ql/test/library-tests/path-resolution/path-resolution.ql index 4fdcf39c6c62..bd522597a2e4 100644 --- a/rust/ql/test/library-tests/path-resolution/path-resolution.ql +++ b/rust/ql/test/library-tests/path-resolution/path-resolution.ql @@ -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) }