-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17913 from geoffw0/unusedvar8
Rust: Fix rust/unused-variable FPs
- Loading branch information
Showing
8 changed files
with
197 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import rust | ||
|
||
/** A deliberately unused variable. */ | ||
/** | ||
* A deliberately unused variable, for example `_` or `_x`. | ||
*/ | ||
class DiscardVariable extends Variable { | ||
DiscardVariable() { this.getName().charAt(0) = "_" } | ||
} | ||
|
||
/** Holds if variable `v` is unused. */ | ||
/** | ||
* Holds if variable `v` is unused. | ||
*/ | ||
predicate isUnused(Variable v) { | ||
// variable is not accessed or initialized | ||
not exists(v.getAnAccess()) and | ||
not exists(v.getInitializer()) and | ||
not v instanceof DiscardVariable and | ||
not v.getPat().isInMacroExpansion() | ||
not exists(v.getInitializer()) | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
predicate isAllowableUnused(Variable v) { | ||
// in a macro expansion | ||
v.getPat().isInMacroExpansion() | ||
} |
167 changes: 91 additions & 76 deletions
167
rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.