Skip to content

Commit 1b7b24e

Browse files
committed
Rust: add Locatable::hasLocationInfo
1 parent f213a2d commit 1b7b24e

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ module Impl {
2525
)
2626
}
2727

28-
/**
29-
* Holds if this element is at the specified location.
30-
* The location spans column `startcolumn` of line `startline` to
31-
* column `endcolumn` of line `endline` in file `filepath`.
32-
* For more information, see
33-
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
34-
*/
35-
predicate hasLocationInfo(
28+
override predicate hasLocationInfo(
3629
string filepath, int startline, int startcolumn, int endline, int endcolumn
3730
) {
3831
argument.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,26 @@ module Impl {
1919
final Location getLocation() {
2020
exists(Raw::Locatable raw |
2121
raw = Synth::convertLocatableToRaw(this) and
22-
(
23-
locatable_locations(raw, result)
24-
or
25-
not exists(Location loc | locatable_locations(raw, loc)) and
26-
result instanceof EmptyLocation
27-
)
22+
locatable_locations(raw, result)
2823
)
2924
}
3025

26+
/**
27+
* Holds if this element is at the specified location.
28+
* The location spans column `startcolumn` of line `startline` to
29+
* column `endcolumn` of line `endline` in file `filepath`.
30+
* For more information, see
31+
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
32+
*/
33+
predicate hasLocationInfo(
34+
string filepath, int startline, int startcolumn, int endline, int endcolumn
35+
) {
36+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
37+
or
38+
not exists(this.getLocation()) and
39+
any(EmptyLocation e).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
40+
}
41+
3142
/**
3243
* Gets the primary file where this element occurs.
3344
*/

0 commit comments

Comments
 (0)