Skip to content

Commit 980cebe

Browse files
aibaarshvitved
authored andcommitted
Rust: fix QL code after removing Crate::getModule()
1 parent f05bed6 commit 980cebe

File tree

5 files changed

+10
-29
lines changed

5 files changed

+10
-29
lines changed

rust/ql/lib/codeql/rust/elements/internal/CrateImpl.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ module Impl {
6060
Crate getADependency() { result = this.getDependency(_) }
6161

6262
/** Gets the source file that defines this crate, if any. */
63-
SourceFile getSourceFile() { result.getFile() = this.getModule().getFile() }
63+
SourceFile getSourceFile() { result.getFile() = this.getLocation().getFile() }
6464

6565
/**
6666
* Gets a source file that belongs to this crate, if any.
6767
*/
6868
SourceFile getASourceFile() { result = this.(CrateItemNode).getASourceFile() }
69-
70-
override Location getLocation() { result = this.getModule().getLocation() }
7169
}
7270
}

rust/ql/lib/codeql/rust/internal/AstConsistency.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) >
2424
/**
2525
* Holds if `e` does not have a `Location`.
2626
*/
27-
query predicate noLocation(Locatable e) {
28-
not exists(e.getLocation()) and
29-
not e.(AstNode).getParentNode*() = any(Crate c).getModule()
30-
}
27+
query predicate noLocation(Locatable e) { not exists(e.getLocation()) }
3128

3229
private predicate multiplePrimaryQlClasses(Element e) {
3330
strictcount(string cls | cls = e.getAPrimaryQlClass() and cls != "VariableAccess") > 1

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,7 @@ abstract private class ModuleLikeNode extends ItemNode {
286286
* Holds if this is a root module, meaning either a source file or
287287
* the entry module of a crate.
288288
*/
289-
predicate isRoot() {
290-
this instanceof SourceFileItemNode
291-
or
292-
this = any(Crate c).getModule()
293-
}
289+
predicate isRoot() { this instanceof SourceFileItemNode }
294290
}
295291

296292
private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
@@ -322,12 +318,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
322318
* or a module, when the crate is defined in a dependency.
323319
*/
324320
pragma[nomagic]
325-
ModuleLikeNode getModuleNode() {
326-
result = super.getSourceFile()
327-
or
328-
not exists(super.getSourceFile()) and
329-
result = super.getModule()
330-
}
321+
ModuleLikeNode getModuleNode() { result = super.getSourceFile() }
331322

332323
/**
333324
* Gets a source file that belongs to this crate, if any.
@@ -351,11 +342,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
351342
/**
352343
* Gets a root module node belonging to this crate.
353344
*/
354-
ModuleLikeNode getARootModuleNode() {
355-
result = this.getASourceFile()
356-
or
357-
result = super.getModule()
358-
}
345+
ModuleLikeNode getARootModuleNode() { result = this.getASourceFile() }
359346

360347
pragma[nomagic]
361348
predicate isPotentialDollarCrateTarget() {
@@ -1104,7 +1091,7 @@ private predicate crateDependencyEdge(ModuleLikeNode m, string name, CrateItemNo
11041091
or
11051092
// paths inside the crate graph use the name of the crate itself as prefix,
11061093
// although that is not valid in Rust
1107-
dep = any(Crate c | name = c.getName() and m = c.getModule())
1094+
dep = any(Crate c | name = c.getName() and m = c.getSourceFile())
11081095
}
11091096

11101097
private predicate useTreeDeclares(UseTree tree, string name) {
@@ -1448,10 +1435,10 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
14481435
* [1]: https://doc.rust-lang.org/core/prelude/index.html
14491436
*/
14501437
private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
1451-
exists(Crate core, ModuleItemNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1438+
exists(Crate core, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
14521439
f = any(Crate c0 | core = c0.getDependency(_)).getASourceFile() and
14531440
core.getName() = "core" and
1454-
mod = core.getModule() and
1441+
mod = core.getSourceFile() and
14551442
prelude = mod.getASuccessorRec("prelude") and
14561443
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
14571444
i = rust.getASuccessorRec(name) and

rust/ql/src/queries/summary/Stats.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ int getQuerySinksCount() { result = count(QuerySink s) }
9191
class CrateElement extends Element {
9292
CrateElement() {
9393
this instanceof Crate or
94-
this instanceof NamedCrate or
95-
this.(AstNode).getParentNode*() = any(Crate c).getModule()
94+
this instanceof NamedCrate
9695
}
9796
}
9897

rust/ql/test/TestUtils.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CrateElement extends Element {
66
CrateElement() {
77
this instanceof Crate or
88
this instanceof NamedCrate or
9-
any(Crate c).getModule() = this.(AstNode).getParentNode*()
9+
any(Crate c).getSourceFile() = this.(AstNode).getParentNode*()
1010
}
1111
}
1212

0 commit comments

Comments
 (0)