Skip to content

Commit

Permalink
Rust: Restrict the query to user code.
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffw0 committed Sep 16, 2024
1 parent fb6fbf6 commit aed44ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
28 changes: 14 additions & 14 deletions rust/ql/src/queries/diagnostics/MissingElements.ql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @name Missing Elements
* @description List all elements that weren't extracted due to unimplemented features or parse errors.
* @description List all elements in the source code directory that weren't extracted due to unimplemented features or parse errors.
* @id rust/diagnostics/missing-elements
*/

Expand All @@ -16,16 +16,6 @@ Location getUnimplementedLocation(Unimplemented node) {
result instanceof EmptyLocation
}

/**
* Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up.
*/
bindingset[l]
string cleanLocationString(Location l) {
if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation
then result = l.toString()
else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string
}

/**
* Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string.
*/
Expand All @@ -39,23 +29,33 @@ string multipleString(int i) {
query predicate listUnimplemented(string location, string msg) {
// something that is not extracted yet
exists(int c |
c = strictcount(Unimplemented n | cleanLocationString(getUnimplementedLocation(n)) = location) and
c =
strictcount(Unimplemented n |
exists(getUnimplementedLocation(n).getFile().getRelativePath()) and
getUnimplementedLocation(n).toString() = location

Check warning

Code scanning / CodeQL

Using 'toString' in query logic Warning

Query logic depends on implementation of 'toString'.
) and
msg = "Not yet implemented" + multipleString(c) + "."
)
}

query predicate listMissingExpr(string location, string msg) {
// gaps in the AST due to parse errors
exists(int c |
c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and
c =
strictcount(MissingExpr e |
exists(e.getFile().getRelativePath()) and e.getLocation().toString() = location

Check warning

Code scanning / CodeQL

Using 'toString' in query logic Warning

Query logic depends on implementation of 'toString'.
) and
msg = "Missing expression" + multipleString(c) + "."
)
}

query predicate listMissingPat(string location, string msg) {
// gaps in the AST due to parse errors
exists(int c |
c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and
c =
strictcount(MissingPat p |
exists(p.getFile().getRelativePath()) and p.getLocation().toString() = location

Check warning

Code scanning / CodeQL

Using 'toString' in query logic Warning

Query logic depends on implementation of 'toString'.
) and
msg = "Missing pattern" + multipleString(c) + "."
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listUnimplemented
| @0:0:0:0 | Not yet implemented (x20). |
| does_not_compile.rs@2:2:2:5 | Not yet implemented. |
| does_not_compile.rs@2:7:2:8 | Not yet implemented. |
| does_not_compile.rs@2:10:2:12 | Not yet implemented. |
Expand Down

0 comments on commit aed44ba

Please sign in to comment.