|
1 | 1 | /**
|
2 | 2 | * @name Missing Elements
|
3 | 3 | * @description List all elements that weren't extracted due to unimplemented features or parse errors.
|
4 |
| - * @kind diagnostic |
5 | 4 | * @id rust/diagnostics/missing-elements
|
6 | 5 | */
|
7 | 6 |
|
8 | 7 | import rust
|
9 | 8 |
|
10 |
| -query predicate listUnimplemented(AstNode n, string msg) { |
11 |
| - // not extracted yet |
12 |
| - n instanceof Unimplemented and |
13 |
| - msg = "Not yet implemented." |
| 9 | +/** |
| 10 | + * Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up. |
| 11 | + */ |
| 12 | +bindingset[l] |
| 13 | +string cleanLocationString(Location l) { |
| 14 | + if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation |
| 15 | + then result = l.toString() |
| 16 | + else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string. |
| 21 | + */ |
| 22 | +bindingset[i] |
| 23 | +string multipleString(int i) { |
| 24 | + i = 1 and result = "" |
| 25 | + or |
| 26 | + i > 1 and result = " (x" + i.toString() + ")" |
| 27 | +} |
| 28 | + |
| 29 | +query predicate listUnimplemented(string location, string msg) { |
| 30 | + // something that is not extracted yet |
| 31 | + exists(int c | |
| 32 | + c = strictcount(Unimplemented n | cleanLocationString(n.getLocation()) = location) and |
| 33 | + msg = "Not yet implemented" + multipleString(c) + "." |
| 34 | + ) |
14 | 35 | }
|
15 | 36 |
|
16 |
| -query predicate listMissingExpr(Expr e, string msg) { |
| 37 | +query predicate listMissingExpr(string location, string msg) { |
17 | 38 | // gaps in the AST due to parse errors
|
18 |
| - e instanceof MissingExpr and |
19 |
| - msg = "Missing expression." |
| 39 | + exists(int c | |
| 40 | + c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and |
| 41 | + msg = "Missing expression" + multipleString(c) + "." |
| 42 | + ) |
20 | 43 | }
|
21 | 44 |
|
22 |
| -query predicate listMissingPat(Pat p, string msg) { |
| 45 | +query predicate listMissingPat(string location, string msg) { |
23 | 46 | // gaps in the AST due to parse errors
|
24 |
| - p instanceof MissingPat and |
25 |
| - msg = "Missing pattern." |
| 47 | + exists(int c | |
| 48 | + c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and |
| 49 | + msg = "Missing pattern" + multipleString(c) + "." |
| 50 | + ) |
26 | 51 | }
|
0 commit comments