Rust: Fix some false positives for rust/unused-variable and rust/unused-value#21009
Rust: Fix some false positives for rust/unused-variable and rust/unused-value#21009geoffw0 merged 6 commits intogithub:mainfrom
Conversation
|
Unfortunately it turns out this change does exclude some correct results (see the test). I'm not sure how I can improve that, short of looking at the case of the variable name (i.e. heuristic). Lets wait for the DCA results and see what we've got. |
|
DCA showed 1076 results removed. I've reviewed a large number of these and nearly all resemble the typical example in the PR comment above. We do lose a tiny number of results where the target really was a (used or unused) variable - I've since narrowed the change slightly to address that (by checking capitalization as well). |
There was a problem hiding this comment.
Pull request overview
This PR fixes common false positives in the rust/unused-variable and rust/unused-value queries by filtering out match arm patterns that begin with uppercase letters, which are typically constants that have been misrecognized as variables due to incorrect extraction or resolution.
- Added logic to the
isAllowableUnusedpredicate to exclude uppercase-starting identifiers in match arms - Added a change note documenting this fix for both affected queries
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rust/ql/src/queries/unusedentities/UnusedVariable.qll | Extended isAllowableUnused predicate to filter out match arm patterns beginning with uppercase letters (typically misrecognized constants) |
| rust/ql/src/change-notes/2025-12-10-unused-variable.md | Added change note documenting the fix for false positives in both rust/unused-variable and rust/unused-value queries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix some common false positive results for the
rust/unused-variableandrust/unused-valuequeries. Typically these results look something like this:Due to incorrect code, incorrect extraction, and/or extraction with the wrong settings
MY_CONSTANTis misrecognized as a variable and the query observes that it is not used. I've been unable to produce a test case but its common in the wild and I expect DCA to produce many fixed examples of this.