From bd1f46b75cda22e22cf406a324daffbfad99525a Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Tue, 1 Jul 2025 09:11:38 +0200 Subject: [PATCH] Rust: Assume prelude is always available in path resolution --- rust/ql/lib/codeql/rust/internal/PathResolution.qll | 8 ++------ .../CONSISTENCY/PathResolutionConsistency.expected | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 2de2e8e4025c..520b924aa32d 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -194,7 +194,7 @@ abstract class ItemNode extends Locatable { Stages::PathResolutionStage::ref() and result = this.getASuccessorRec(name) or - preludeEdge(this, name, result) and not declares(this, _, name) + preludeEdge(this, name, result) or this instanceof SourceFile and builtin(name, result) @@ -1505,12 +1505,8 @@ private predicate externCrateEdge(ExternCrateItemNode ec, string name, CrateItem */ pragma[nomagic] private predicate preludeEdge(SourceFile f, string name, ItemNode i) { + not declares(f, _, name) and exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust | - f = any(Crate c0 | stdOrCore = c0.getDependency(_) or stdOrCore = c0).getASourceFile() - or - // Give builtin files access to the prelude - f instanceof BuiltinSourceFile - | stdOrCore.getName() = ["std", "core"] and mod = stdOrCore.getSourceFile() and prelude = mod.getASuccessorRec("prelude") and diff --git a/rust/ql/test/library-tests/variables/CONSISTENCY/PathResolutionConsistency.expected b/rust/ql/test/library-tests/variables/CONSISTENCY/PathResolutionConsistency.expected index 065aa039536d..b95bb1ccc856 100644 --- a/rust/ql/test/library-tests/variables/CONSISTENCY/PathResolutionConsistency.expected +++ b/rust/ql/test/library-tests/variables/CONSISTENCY/PathResolutionConsistency.expected @@ -1,5 +1,3 @@ multipleCallTargets | main.rs:85:19:85:40 | ...::from(...) | | main.rs:102:19:102:40 | ...::from(...) | -| main.rs:374:5:374:27 | ... .add_assign(...) | -| main.rs:459:9:459:23 | z.add_assign(...) |