-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Rust: remove queries that no longer work"
This reverts commit e19bca0.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @name Unextracted Elements | ||
* @description List all elements that weren't extracted due to unimplemented features or parse errors. | ||
* @id rust/diagnostics/unextracted-elements | ||
*/ | ||
|
||
import rust | ||
|
||
/** | ||
* Gets a location for an `Unimplemented` node. | ||
*/ | ||
Location getUnimplementedLocation(Unimplemented node) { | ||
result = node.(Locatable).getLocation() | ||
or | ||
not node instanceof Locatable and | ||
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. | ||
*/ | ||
bindingset[i] | ||
string multipleString(int i) { | ||
i = 1 and result = "" | ||
or | ||
i > 1 and result = " (x" + i.toString() + ")" | ||
} | ||
|
||
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 | ||
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 | ||
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 | ||
msg = "Missing pattern" + multipleString(c) + "." | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
rust/ql/test/query-tests/diagnostics/UnextractedElements.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
listUnimplemented | ||
| @0:0:0:0 | Not yet implemented (x14). | | ||
| 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. | | ||
| does_not_compile.rs@2:14:2:20 | Not yet implemented. | | ||
| does_not_compile.rs@2:22:2:25 | Not yet implemented. | | ||
| does_not_compile.rs@2:27:2:30 | Not yet implemented. | | ||
| main.rs@16:5:16:22 | Not yet implemented. | | ||
| main.rs@17:5:17:21 | Not yet implemented. | | ||
| my_struct.rs@2:1:13:1 | Not yet implemented. | | ||
| my_struct.rs@24:9:27:9 | Not yet implemented. | | ||
| my_struct.rs@25:19:25:30 | Not yet implemented. | | ||
| my_struct.rs@29:5:29:5 | Not yet implemented. | | ||
listMissingExpr | ||
listMissingPat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/diagnostics/UnextractedElements.ql |