Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
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
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.Bultins
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.

The module name Bultins appears misspelled; it should likely be Builtins to match the framework's naming.

Copilot uses AI. Check for mistakes.

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