Skip to content

Commit 8f1c1a8

Browse files
committed
Revert "Rust: remove queries that no longer work"
This reverts commit e19bca0.
1 parent cc63abf commit 8f1c1a8

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @name Unextracted Elements
3+
* @description List all elements that weren't extracted due to unimplemented features or parse errors.
4+
* @id rust/diagnostics/unextracted-elements
5+
*/
6+
7+
import rust
8+
9+
/**
10+
* Gets a location for an `Unimplemented` node.
11+
*/
12+
Location getUnimplementedLocation(Unimplemented node) {
13+
result = node.(Locatable).getLocation()
14+
or
15+
not node instanceof Locatable and
16+
result instanceof EmptyLocation
17+
}
18+
19+
/**
20+
* Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up.
21+
*/
22+
bindingset[l]
23+
string cleanLocationString(Location l) {
24+
if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation
25+
then result = l.toString()
26+
else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string
27+
}
28+
29+
/**
30+
* Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string.
31+
*/
32+
bindingset[i]
33+
string multipleString(int i) {
34+
i = 1 and result = ""
35+
or
36+
i > 1 and result = " (x" + i.toString() + ")"
37+
}
38+
39+
query predicate listUnimplemented(string location, string msg) {
40+
// something that is not extracted yet
41+
exists(int c |
42+
c = strictcount(Unimplemented n | cleanLocationString(getUnimplementedLocation(n)) = location) and
43+
msg = "Not yet implemented" + multipleString(c) + "."
44+
)
45+
}
46+
47+
query predicate listMissingExpr(string location, string msg) {
48+
// gaps in the AST due to parse errors
49+
exists(int c |
50+
c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and
51+
msg = "Missing expression" + multipleString(c) + "."
52+
)
53+
}
54+
55+
query predicate listMissingPat(string location, string msg) {
56+
// gaps in the AST due to parse errors
57+
exists(int c |
58+
c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and
59+
msg = "Missing pattern" + multipleString(c) + "."
60+
)
61+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
listUnimplemented
2+
| @0:0:0:0 | Not yet implemented (x14). |
3+
| does_not_compile.rs@2:2:2:5 | Not yet implemented. |
4+
| does_not_compile.rs@2:7:2:8 | Not yet implemented. |
5+
| does_not_compile.rs@2:10:2:12 | Not yet implemented. |
6+
| does_not_compile.rs@2:14:2:20 | Not yet implemented. |
7+
| does_not_compile.rs@2:22:2:25 | Not yet implemented. |
8+
| does_not_compile.rs@2:27:2:30 | Not yet implemented. |
9+
| main.rs@16:5:16:22 | Not yet implemented. |
10+
| main.rs@17:5:17:21 | Not yet implemented. |
11+
| my_struct.rs@2:1:13:1 | Not yet implemented. |
12+
| my_struct.rs@24:9:27:9 | Not yet implemented. |
13+
| my_struct.rs@25:19:25:30 | Not yet implemented. |
14+
| my_struct.rs@29:5:29:5 | Not yet implemented. |
15+
listMissingExpr
16+
listMissingPat
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/diagnostics/UnextractedElements.ql

0 commit comments

Comments
 (0)