diff --git a/rust/ql/src/change-notes/2025-12-10-unused-variable.md b/rust/ql/src/change-notes/2025-12-10-unused-variable.md new file mode 100644 index 000000000000..7391255e608c --- /dev/null +++ b/rust/ql/src/change-notes/2025-12-10-unused-variable.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Fixed common false positives for the `rust/unused-variable` and `rust/unused-value` queries. diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.qll b/rust/ql/src/queries/unusedentities/UnusedVariable.qll index c0684636e77b..744af559dd2a 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.qll +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.qll @@ -43,4 +43,10 @@ predicate isAllowableUnused(Variable v) { or // a 'self' variable v.getText() = "self" + or + // a common source of false positives is match arms containing constants + // (typically beginning with a capital letter) that are misrecognized as a + // variable, having not been correctly resolved. + v.getPat().getParentNode() instanceof MatchArm and + v.getText().charAt(0).isUppercase() }