mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Merge pull request #17465 from geoffw0/missing
Rust: Add Missing Elements query
This commit is contained in:
61
rust/ql/src/queries/diagnostics/UnextractedElements.ql
Normal file
61
rust/ql/src/queries/diagnostics/UnextractedElements.ql
Normal file
@@ -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) + "."
|
||||
)
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/UnextractedElements.ql
|
||||
@@ -10,8 +10,8 @@ mod my_macro;
|
||||
|
||||
// another comment
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!"); // another comment
|
||||
fn main() { // another comment
|
||||
//println!("Hello, world!"); // currently causes consistency issues
|
||||
|
||||
my_struct::my_func();
|
||||
my_macro::my_func();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
macro_rules! myMacro {
|
||||
() => {
|
||||
println!("Hello, world!");
|
||||
//println!("Hello, world!"); // currently causes consistency issues
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user