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 {
7
7
8
8
/** Holds if variable `v` is unused. */
9
9
predicate isUnused ( Variable v ) {
10
+ // variable is accessed or initialized
10
11
not exists ( v .getAnAccess ( ) ) and
11
12
not exists ( v .getInitializer ( ) ) and
13
+ // variable is intentionally unused
12
14
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 ( ) )
14
18
}
Original file line number Diff line number Diff line change 15
15
| main.rs:373:9:373:9 | x | Variable $@ is assigned a value that is never used. | main.rs:373:9:373:9 | x | x |
16
16
| main.rs:381:17:381:17 | x | Variable $@ is assigned a value that is never used. | main.rs:381:17:381:17 | x | x |
17
17
| 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 |
18
22
| 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 |
19
23
| 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 |
20
24
| 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 19
19
| main.rs:427:26:427:28 | val | Variable 'val' is not used. |
20
20
| main.rs:430:21:430:23 | acc | Variable 'acc' is not used. |
21
21
| 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. |
26
22
| 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() {
491
491
492
492
pub struct my_declaration {
493
493
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 ]
497
497
}
498
498
499
- type MyType = fn ( x : i32 ) -> i32 ; // $ SPURIOUS: Alert[rust/unused-variable ]
499
+ type MyType = fn ( x : i32 ) -> i32 ; // $ SPURIOUS: Alert[rust/unused-value ]
500
500
501
501
trait MyTrait {
502
502
fn my_func2 ( & self , x : i32 ) -> i32 ;
You can’t perform that action at this time.
0 commit comments