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
5 changes: 4 additions & 1 deletion rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
private import rust
private import codeql.rust.elements.internal.generated.ParentChild
private import codeql.rust.internal.CachedStages
private import codeql.rust.frameworks.stdlib.Bultins as Builtins
private import codeql.rust.frameworks.stdlib.Builtins as Builtins

private newtype TNamespace =
TTypeNamespace() or
Expand Down Expand Up @@ -374,6 +374,9 @@ class CrateItemNode extends ItemNode instanceof Crate {
not file = child.(SourceFileItemNode).getSuper() and
file = super.getSourceFile()
)
or
this.getName() = "core" and
child instanceof Builtins::BuiltinType
Comment on lines +378 to +379
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding parentheses around the this.getName() = "core" and child instanceof Builtins::BuiltinType clause to make grouping explicit and improve readability.

Suggested change
this.getName() = "core" and
child instanceof Builtins::BuiltinType
(this.getName() = "core" and
child instanceof Builtins::BuiltinType)

Copilot uses AI. Check for mistakes.
}

override string getCanonicalPath(Crate c) { c = this and result = Crate.super.getName() }
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/internal/TypeInference.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private import Type as T
private import TypeMention
private import codeql.typeinference.internal.TypeInference
private import codeql.rust.frameworks.stdlib.Stdlib
private import codeql.rust.frameworks.stdlib.Bultins as Builtins
private import codeql.rust.frameworks.stdlib.Builtins as Builtins

class Type = T::Type;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
canonicalPath
| anonymous.rs:3:1:32:1 | fn canonicals | test::anonymous::canonicals |
| anonymous.rs:34:1:36:1 | fn other | test::anonymous::other |
| {EXTERNAL LOCATION} | fn trim | <core::str>::trim |
| lib.rs:1:1:1:14 | mod anonymous | test::anonymous |
| lib.rs:2:1:2:12 | mod regular | test::regular |
| regular.rs:1:1:2:18 | struct Struct | test::regular::Struct |
Expand Down
14 changes: 13 additions & 1 deletion rust/ql/test/extractor-tests/canonical_path/canonical_paths.ql
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import rust
import TestUtils
private import codeql.rust.internal.PathResolution
private import codeql.rust.frameworks.stdlib.Builtins

query predicate canonicalPath(Addressable a, string path) {
toBeTested(a) and
(
toBeTested(a)
or
// test that we also generate canonical paths for builtins
a =
any(ImplItemNode i |
i.resolveSelfTy() instanceof Str and
not i.(Impl).hasTrait()
).getAnAssocItem() and
a.(Function).getName().getText() = "trim"
) and
path = a.getCanonicalPath(_)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: canonical_paths.ql
postprocess: utils/test/ExternalLocationPostProcessing.ql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
canonicalPath
| anonymous.rs:6:1:35:1 | fn canonicals | test::anonymous::canonicals |
| anonymous.rs:37:1:39:1 | fn other | test::anonymous::other |
| {EXTERNAL LOCATION} | fn trim | <core::str>::trim |
| lib.rs:1:1:1:14 | mod anonymous | test::anonymous |
| lib.rs:2:1:2:12 | mod regular | test::regular |
| regular.rs:4:1:5:18 | struct Struct | test::regular::Struct |
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
extractor-tests/canonical_path/canonical_paths.ql
query: extractor-tests/canonical_path/canonical_paths.ql
postprocess: utils/test/ExternalLocationPostProcessing.ql