Rust: Restrict the query to user code.

This commit is contained in:
Geoffrey White
2024-09-16 12:55:49 +01:00
parent fb6fbf6d21
commit aed44ba5f3
2 changed files with 14 additions and 15 deletions

View File

@@ -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
*/
@@ -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.
*/
@@ -39,7 +29,11 @@ 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
) and
msg = "Not yet implemented" + multipleString(c) + "."
)
}
@@ -47,7 +41,10 @@ query predicate listUnimplemented(string location, string msg) {
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
) and
msg = "Missing expression" + multipleString(c) + "."
)
}
@@ -55,7 +52,10 @@ query predicate listMissingExpr(string location, string msg) {
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
) and
msg = "Missing pattern" + multipleString(c) + "."
)
}

View File

@@ -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. |