diff --git a/rust/ql/src/queries/diagnostics/MissingElements.ql b/rust/ql/src/queries/diagnostics/MissingElements.ql index a6ca358fb55e..ed82d0bcbeaa 100644 --- a/rust/ql/src/queries/diagnostics/MissingElements.ql +++ b/rust/ql/src/queries/diagnostics/MissingElements.ql @@ -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) + "." ) } diff --git a/rust/ql/test/query-tests/diagnostics/MissingElements.expected b/rust/ql/test/query-tests/diagnostics/MissingElements.expected index 064a9fe1a0d8..fe3f2bce17bb 100644 --- a/rust/ql/test/query-tests/diagnostics/MissingElements.expected +++ b/rust/ql/test/query-tests/diagnostics/MissingElements.expected @@ -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. |