Skip to content

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Dec 10, 2025

Fix some common false positive results for the rust/unused-variable and rust/unused-value queries. Typically these results look something like this:

match foo {
  MY_CONSTANT => { ... }
  ...
}

Due to incorrect code, incorrect extraction, and/or extraction with the wrong settings MY_CONSTANT is 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.

@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label Dec 10, 2025
@geoffw0
Copy link
Contributor Author

geoffw0 commented Dec 10, 2025

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.

@geoffw0
Copy link
Contributor Author

geoffw0 commented Dec 11, 2025

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).

@geoffw0 geoffw0 marked this pull request as ready for review December 11, 2025 18:10
@geoffw0 geoffw0 requested a review from a team as a code owner December 11, 2025 18:10
Copilot AI review requested due to automatic review settings December 11, 2025 18:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 isAllowableUnused predicate 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants