mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #19732 from hvitved/rust/builtin-canonical-paths
Rust: Generate canonical paths for builtins
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
override string getCanonicalPath(Crate c) { c = this and result = Crate.super.getName() }
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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(_)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
query: canonical_paths.ql
|
||||
postprocess: utils/test/ExternalLocationPostProcessing.ql
|
||||
@@ -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 |
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
extractor-tests/canonical_path/canonical_paths.ql
|
||||
query: extractor-tests/canonical_path/canonical_paths.ql
|
||||
postprocess: utils/test/ExternalLocationPostProcessing.ql
|
||||
Reference in New Issue
Block a user