Skip to content

Commit d88bae9

Browse files
committed
Rust: Narrow the exclusion a little.
1 parent f1d241f commit d88bae9

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ predicate isAllowableUnused(Variable v) {
4444
// a 'self' variable
4545
v.getText() = "self"
4646
or
47-
// a common source of false positives is match arms that are misrecognized as
48-
// a variable, having not been correctly resolved
49-
v.getPat().getParentNode() instanceof MatchArm
47+
// a common source of false positives is match arms containing constants
48+
// (typically beginning with a capital letter) that are misrecognized as a
49+
// variable, having not been correctly resolved.
50+
v.getPat().getParentNode() instanceof MatchArm and
51+
v.getText().charAt(0).isUppercase()
5052
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| main.rs:307:13:307:15 | num | Variable 'num' is not used. |
1111
| main.rs:342:25:342:25 | y | Variable 'y' is not used. |
1212
| main.rs:345:28:345:28 | a | Variable 'a' is not used. |
13+
| main.rs:348:9:348:9 | p | Variable 'p' is not used. |
1314
| main.rs:366:9:366:13 | right | Variable 'right' is not used. |
1415
| main.rs:372:9:372:14 | right2 | Variable 'right2' is not used. |
1516
| main.rs:383:13:383:13 | y | Variable 'y' 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
@@ -345,7 +345,7 @@ fn if_lets_matches() {
345345
MyPoint { x: 3, y: a } => { // $ Alert[rust/unused-variable]
346346
}
347347
MyPoint { x: 4, .. } => {}
348-
p => { // $ MISSING: Alert[rust/unused-variable]
348+
p => { // $ Alert[rust/unused-variable]
349349
}
350350
}
351351

0 commit comments

Comments
 (0)