-
Notifications
You must be signed in to change notification settings - Fork 2k
Rust: Improve rust/unused-variable and rust/unused-value #18952
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
Changes from 6 commits
abe14ba
b2e3352
e0839a3
cc902a6
fe139e5
3d0e44e
aa35e82
bb39955
7717f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,20 @@ predicate isUnused(Variable v) { | |
| not exists(v.getInitializer()) | ||
| } | ||
|
|
||
| /** | ||
| * A callable for which we have incomplete information, for example because an unexpanded | ||
| * macro call is present. These callables are prone to false positive results from unused | ||
| * entities queries, unless they are excluded from results. | ||
| */ | ||
| class IncompleteCallable extends Callable { | ||
| IncompleteCallable() { | ||
| exists(MacroExpr me | | ||
| me.getEnclosingCallable() = this and | ||
| not me.getMacroCall().hasExpanded() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Holds if variable `v` is in a context where we may not find a use for it, | ||
| * but that's expected and should not be considered a problem. | ||
|
|
@@ -24,6 +38,9 @@ predicate isAllowableUnused(Variable v) { | |
| // in a macro expansion | ||
| v.getPat().isInMacroExpansion() | ||
| or | ||
| // declared in an incomplete callable | ||
| v.getEnclosingCfgScope() instanceof IncompleteCallable | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this works, it would perhaps be more correct to only exclude results when there is an unexpandable macro in the scope that the variable is defined. However, I realize that the concept of variable scope is not currently exposed, so perhaps that is better done follow-up.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is required to expose the concept of a variable scope? I've added a test that exposes the situation I think we're talking about here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would have to expose the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I've added it to the existing improvements issue for Is there any reason
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Only that we haven't needed it before. We may also have to change it slightly, for example right now let x = ...;
let y = ...; |
||
| or | ||
| // a 'self' variable | ||
| v.getText() = "self" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| extractionWarning | ||
| | main.rs:512:5:512:28 | macro expansion failed: could not resolve macro 'undefined_macro_call' | | ||
| | main.rs:516:5:516:28 | macro expansion failed: could not resolve macro 'undefined_macro_call' | | ||
| | main.rs:522:13:522:36 | macro expansion failed: could not resolve macro 'undefined_macro_call' | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| qltest_cargo_check: false | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.