Rust: Narrow the exclusion a little.

This commit is contained in:
Geoffrey White
2025-12-11 17:57:16 +00:00
parent f1d241f810
commit d88bae9ec2
3 changed files with 7 additions and 4 deletions

View File

@@ -44,7 +44,9 @@ predicate isAllowableUnused(Variable v) {
// a 'self' variable // a 'self' variable
v.getText() = "self" v.getText() = "self"
or or
// a common source of false positives is match arms that are misrecognized as // a common source of false positives is match arms containing constants
// a variable, having not been correctly resolved // (typically beginning with a capital letter) that are misrecognized as a
v.getPat().getParentNode() instanceof MatchArm // variable, having not been correctly resolved.
v.getPat().getParentNode() instanceof MatchArm and
v.getText().charAt(0).isUppercase()
} }

View File

@@ -10,6 +10,7 @@
| main.rs:307:13:307:15 | num | Variable 'num' is not used. | | main.rs:307:13:307:15 | num | Variable 'num' is not used. |
| main.rs:342:25:342:25 | y | Variable 'y' is not used. | | main.rs:342:25:342:25 | y | Variable 'y' is not used. |
| main.rs:345:28:345:28 | a | Variable 'a' is not used. | | main.rs:345:28:345:28 | a | Variable 'a' is not used. |
| main.rs:348:9:348:9 | p | Variable 'p' is not used. |
| main.rs:366:9:366:13 | right | Variable 'right' is not used. | | main.rs:366:9:366:13 | right | Variable 'right' is not used. |
| main.rs:372:9:372:14 | right2 | Variable 'right2' is not used. | | main.rs:372:9:372:14 | right2 | Variable 'right2' is not used. |
| main.rs:383:13:383:13 | y | Variable 'y' is not used. | | main.rs:383:13:383:13 | y | Variable 'y' is not used. |

View File

@@ -345,7 +345,7 @@ fn if_lets_matches() {
MyPoint { x: 3, y: a } => { // $ Alert[rust/unused-variable] MyPoint { x: 3, y: a } => { // $ Alert[rust/unused-variable]
} }
MyPoint { x: 4, .. } => {} MyPoint { x: 4, .. } => {}
p => { // $ MISSING: Alert[rust/unused-variable] p => { // $ Alert[rust/unused-variable]
} }
} }