File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed
src/queries/unusedentities
test/query-tests/unusedentities Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,12 @@ class DiscardVariable extends Variable {
77
88/** Holds if variable `v` is unused. */
99predicate isUnused ( Variable v ) {
10+ // variable is accessed or initialized
1011 not exists ( v .getAnAccess ( ) ) and
1112 not exists ( v .getInitializer ( ) ) and
13+ // variable is intentionally unused
1214 not v instanceof DiscardVariable and
13- not v .getPat ( ) .isInMacroExpansion ( )
15+ // variable is in a context where is may not have a use
16+ not v .getPat ( ) .isInMacroExpansion ( ) and
17+ not exists ( FnPtrType fp | fp .getParamList ( ) .getParam ( _) .getPat ( ) = v .getPat ( ) )
1418}
Original file line number Diff line number Diff line change 1515| main.rs:373:9:373:9 | x | Variable $@ is assigned a value that is never used. | main.rs:373:9:373:9 | x | x |
1616| main.rs:381:17:381:17 | x | Variable $@ is assigned a value that is never used. | main.rs:381:17:381:17 | x | x |
1717| main.rs:482:9:482:9 | c | Variable $@ is assigned a value that is never used. | main.rs:482:9:482:9 | c | c |
18+ | main.rs:494:16:494:16 | x | Variable $@ is assigned a value that is never used. | main.rs:494:16:494:16 | x | x |
19+ | main.rs:495:16:495:16 | y | Variable $@ is assigned a value that is never used. | main.rs:495:16:495:16 | y | y |
20+ | main.rs:496:12:496:12 | z | Variable $@ is assigned a value that is never used. | main.rs:496:12:496:12 | z | z |
21+ | main.rs:499:18:499:18 | x | Variable $@ is assigned a value that is never used. | main.rs:499:18:499:18 | x | x |
1822| more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 |
1923| more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr |
2024| more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr |
Original file line number Diff line number Diff line change 1919| main.rs:427:26:427:28 | val | Variable 'val' is not used. |
2020| main.rs:430:21:430:23 | acc | Variable 'acc' is not used. |
2121| main.rs:451:9:451:14 | unused | Variable 'unused' is not used. |
22- | main.rs:494:16:494:16 | x | Variable 'x' is not used. |
23- | main.rs:495:16:495:16 | y | Variable 'y' is not used. |
24- | main.rs:496:12:496:12 | z | Variable 'z' is not used. |
25- | main.rs:499:18:499:18 | x | Variable 'x' is not used. |
2622| more.rs:24:9:24:11 | val | Variable 'val' is not used. |
Original file line number Diff line number Diff line change @@ -491,12 +491,12 @@ fn references() {
491491
492492pub struct my_declaration {
493493 field1 : fn ( i32 ) -> i32 ,
494- field2 : fn ( x : i32 ) -> i32 , // $ SPURIOUS: Alert[rust/unused-variable ]
495- field3 : fn ( y : // $ SPURIOUS: Alert[rust/unused-variable ]
496- fn ( z : i32 ) -> i32 ) -> i32 , // $ SPURIOUS: Alert[rust/unused-variable ]
494+ field2 : fn ( x : i32 ) -> i32 , // $ SPURIOUS: Alert[rust/unused-value ]
495+ field3 : fn ( y : // $ SPURIOUS: Alert[rust/unused-value ]
496+ fn ( z : i32 ) -> i32 ) -> i32 , // $ SPURIOUS: Alert[rust/unused-value ]
497497}
498498
499- type MyType = fn ( x : i32 ) -> i32 ; // $ SPURIOUS: Alert[rust/unused-variable ]
499+ type MyType = fn ( x : i32 ) -> i32 ; // $ SPURIOUS: Alert[rust/unused-value ]
500500
501501trait MyTrait {
502502 fn my_func2 ( & self , x : i32 ) -> i32 ;
You can’t perform that action at this time.
0 commit comments