Skip to content

Commit 281f8b1

Browse files
committed
Rust: Fix the unwanted results.
1 parent e52e1b0 commit 281f8b1

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

rust/ql/src/queries/unusedentities/UnusedVariable.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ predicate isUnused(Variable v) {
2323
predicate isAllowableUnused(Variable v) {
2424
// in a macro expansion
2525
v.getPat().isInMacroExpansion()
26+
or
27+
// a 'self' variable
28+
v.getName() = "self"
2629
}

rust/ql/test/query-tests/unusedentities/UnusedVariable.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
| main.rs:29:9:29:9 | a | Variable 'a' is not used. |
2-
| main.rs:89:19:89:22 | self | Variable 'self' is not used. |
32
| main.rs:98:13:98:13 | d | Variable 'd' is not used. |
43
| main.rs:147:5:147:5 | y | Variable 'y' is not used. |
54
| main.rs:174:9:174:9 | x | Variable 'x' is not used. |

rust/ql/test/query-tests/unusedentities/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl MyStruct {
8686
return self.val;
8787
}
8888

89-
fn get_flags(&self) -> i64 { // $ SPURIOUS: Alert[rust/unused-variable]
89+
fn get_flags(&self) -> i64 {
9090
return 0;
9191
}
9292
}

0 commit comments

Comments
 (0)