-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust: Fix rust/unused-variable FPs #17913
Conversation
…ust/unused-value as well.
DCA shows the total number of results for |
// variable is in a context where is may not have a use | ||
not v.getPat().isInMacroExpansion() and | ||
not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) | ||
not exists(v.getInitializer()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hvitved Should there be a "write access" for a variable with an initializer? The following two examples should probably be considered equivalent.
let x : i32 = 10;
and
let x : i32;
x = 10;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I have plans to flip this behaviour so that both would be considered an unused variable (and not an unused value). There's an issue tracking this, it will probably be simple, but I haven't got around to it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The x
in let x : i 32 = 10;
is a pattern and not an expression, so making it a write access is not that natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I had never imagined that most of the false positives originated from function pointer types.
The second DCA run LGTM.
One project in particular uses them a huge amount. |
Co-authored-by: Simon Friis Vindum <[email protected]>
Add more test cases for
rust/unused-variable
, inspired by syntax in real world false positive results for the query. I could only get one pattern to reproduce in the test and I've fixed it here.In one of our largest DCA databases this reduces the total number of results from 212,420 -> 100. A DCA run will confirm the overall picture.