File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
src/queries/unusedentities
test/query-tests/unusedentities Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 11
11
import rust
12
12
import UnusedVariable
13
13
14
+ /**
15
+ * A callable for which we have incomplete information, for example because an unexpanded
16
+ * macro call is present. These callables are prone to false positive results from unused
17
+ * entities queries, unless they are excluded from results.
18
+ */
19
+ class IncompleteCallable extends Callable {
20
+ IncompleteCallable ( ) {
21
+ exists ( MacroExpr me |
22
+ me .getEnclosingCallable ( ) = this and
23
+ not me .getMacroCall ( ) .hasExpanded ( )
24
+ )
25
+ }
26
+ }
27
+
14
28
from Variable v
15
29
where
16
30
isUnused ( v ) and
17
31
not isAllowableUnused ( v ) and
18
- not v instanceof DiscardVariable
32
+ not v instanceof DiscardVariable and
33
+ not v .getEnclosingCfgScope ( ) instanceof IncompleteCallable
19
34
select v , "Variable '" + v + "' is not used."
Original file line number Diff line number Diff line change 19
19
| main.rs:431:26:431:28 | val | Variable 'val' is not used. |
20
20
| main.rs:434:21:434:23 | acc | Variable 'acc' is not used. |
21
21
| main.rs:455:9:455:14 | unused | Variable 'unused' is not used. |
22
- | main.rs:521:12:521:12 | n | Variable 'n' is not used. |
23
22
| more.rs:24:9:24:11 | val | Variable 'val' is not used. |
Original file line number Diff line number Diff line change @@ -518,7 +518,7 @@ fn macros4() {
518
518
519
519
fn macros5 ( ) {
520
520
match std:: env:: args ( ) . nth ( 1 ) . unwrap ( ) . parse :: < u16 > ( ) {
521
- Ok ( n) => { // $ SPURIOUS: Alert[rust/unused-variable]
521
+ Ok ( n) => {
522
522
undefined_macro_call ! ( n) ;
523
523
}
524
524
_ => { }
You can’t perform that action at this time.
0 commit comments