Skip to content

Commit 93e8534

Browse files
authored
Merge pull request #21009 from geoffw0/varfps
Rust: Fix some false positives for rust/unused-variable and rust/unused-value
2 parents 949cfc3 + 01f9b42 commit 93e8534

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed common false positives for the `rust/unused-variable` and `rust/unused-value` queries.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ predicate isAllowableUnused(Variable v) {
4343
or
4444
// a 'self' variable
4545
v.getText() = "self"
46+
or
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()
4652
}

0 commit comments

Comments
 (0)