Skip to content

Commit 69eed04

Browse files
committed
Rust: fix QL code after removing Crate::getModule()
1 parent 25fadbd commit 69eed04

File tree

5 files changed

+11
-29
lines changed

5 files changed

+11
-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/frameworks/stdlib/Stdlib.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class OptionEnum extends Enum {
3232
// todo: replace with canonical path, once calculated in QL
3333
exists(Crate core, Module m |
3434
core.getName() = "core" and
35-
m = core.getModule().getItemList().getAnItem() and
35+
m = core.getSourceFile().getAnItem() and
3636
m.getName().getText() = "option" and
3737
this = m.getItemList().getAnItem() and
3838
this.getName().getText() = "Option"
@@ -53,7 +53,7 @@ class ResultEnum extends Enum {
5353
// todo: replace with canonical path, once calculated in QL
5454
exists(Crate core, Module m |
5555
core.getName() = "core" and
56-
m = core.getModule().getItemList().getAnItem() and
56+
m = core.getSourceFile().getAnItem() and
5757
m.getName().getText() = "result" and
5858
this = m.getItemList().getAnItem() and
5959
this.getName().getText() = "Result"

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
@@ -245,11 +245,7 @@ abstract private class ModuleLikeNode extends ItemNode {
245245
* Holds if this is a root module, meaning either a source file or
246246
* the entry module of a crate.
247247
*/
248-
predicate isRoot() {
249-
this instanceof SourceFileItemNode
250-
or
251-
this = any(Crate c).getModule()
252-
}
248+
predicate isRoot() { this instanceof SourceFileItemNode }
253249
}
254250

255251
private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
@@ -277,12 +273,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
277273
* or a module, when the crate is defined in a dependency.
278274
*/
279275
pragma[nomagic]
280-
ModuleLikeNode getModuleNode() {
281-
result = super.getSourceFile()
282-
or
283-
not exists(super.getSourceFile()) and
284-
result = super.getModule()
285-
}
276+
ModuleLikeNode getModuleNode() { result = super.getSourceFile() }
286277

287278
/**
288279
* Gets a source file that belongs to this crate, if any.
@@ -306,11 +297,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
306297
/**
307298
* Gets a root module node belonging to this crate.
308299
*/
309-
ModuleLikeNode getARootModuleNode() {
310-
result = this.getASourceFile()
311-
or
312-
result = super.getModule()
313-
}
300+
ModuleLikeNode getARootModuleNode() { result = this.getASourceFile() }
314301

315302
pragma[nomagic]
316303
predicate isPotentialDollarCrateTarget() {
@@ -829,7 +816,7 @@ private predicate crateDependencyEdge(ModuleLikeNode m, string name, CrateItemNo
829816
or
830817
// paths inside the crate graph use the name of the crate itself as prefix,
831818
// although that is not valid in Rust
832-
dep = any(Crate c | name = c.getName() and m = c.getModule())
819+
dep = any(Crate c | name = c.getName() and m = c.getSourceFile())
833820
}
834821

835822
private predicate useTreeDeclares(UseTree tree, string name) {
@@ -1173,10 +1160,10 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
11731160
* [1]: https://doc.rust-lang.org/core/prelude/index.html
11741161
*/
11751162
private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
1176-
exists(Crate core, ModuleItemNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1163+
exists(Crate core, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
11771164
f = any(Crate c0 | core = c0.getDependency(_)).getASourceFile() and
11781165
core.getName() = "core" and
1179-
mod = core.getModule() and
1166+
mod = core.getSourceFile() and
11801167
prelude = mod.getASuccessorRec("prelude") and
11811168
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
11821169
i = rust.getASuccessorRec(name) and

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)