Skip to content

Rust: Also take the std prelude into account when resolving paths #19611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
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
12 changes: 7 additions & 5 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1404,18 +1404,20 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
}

/**
* Holds if `i` is available inside `f` because it is reexported in [the prelude][1].
* Holds if `i` is available inside `f` because it is reexported in
* [the `core` prelude][1] or [the `std` prelude][2].
*
* We don't yet have access to prelude information from the extractor, so for now
* we include all the preludes for Rust: 2015, 2018, 2021, and 2024.
*
* [1]: https://doc.rust-lang.org/core/prelude/index.html
* [2]: https://doc.rust-lang.org/std/prelude/index.html
*/
private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
exists(Crate core, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
f = any(Crate c0 | core = c0.getDependency(_) or core = c0).getASourceFile() and
core.getName() = "core" and
mod = core.getSourceFile() and
exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
f = any(Crate c0 | stdOrCore = c0.getDependency(_) or stdOrCore = c0).getASourceFile() and
stdOrCore.getName() = ["std", "core"] and
mod = stdOrCore.getSourceFile() and
prelude = mod.getASuccessorRec("prelude") and
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
i = rust.getASuccessorRec(name) and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
multiplePathResolutions
| main.rs:218:14:218:17 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:218:14:218:17 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:219:13:219:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:219:13:219:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:220:13:220:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:220:13:220:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:221:13:221:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:221:13:221:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:222:13:222:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:222:13:222:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:223:13:223:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:223:13:223:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:224:13:224:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
| main.rs:224:13:224:16 | libc | file://:0:0:0:0 | Crate([email protected]) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
multiplePathResolutions
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate([email protected]) |
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate([email protected]) |
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate([email protected]) |
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate([email protected]) |
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate([email protected]) |
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate([email protected]) |