mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #19292 from github/aibaars/rust-shadow-prelude
Rust: allow shadowing of prelude items
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -322,6 +322,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 |
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user