mirror of
https://github.com/github/codeql.git
synced 2026-04-18 13:34:02 +02:00
Rust: Fix unused variable FPs due to unexpanded macro calls.
This commit is contained in:
@@ -11,9 +11,24 @@
|
||||
import rust
|
||||
import UnusedVariable
|
||||
|
||||
/**
|
||||
* 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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
from Variable v
|
||||
where
|
||||
isUnused(v) and
|
||||
not isAllowableUnused(v) and
|
||||
not v instanceof DiscardVariable
|
||||
not v instanceof DiscardVariable and
|
||||
not v.getEnclosingCfgScope() instanceof IncompleteCallable
|
||||
select v, "Variable '" + v + "' is not used."
|
||||
|
||||
@@ -19,5 +19,4 @@
|
||||
| main.rs:431:26:431:28 | val | Variable 'val' is not used. |
|
||||
| main.rs:434:21:434:23 | acc | Variable 'acc' is not used. |
|
||||
| main.rs:455:9:455:14 | unused | Variable 'unused' is not used. |
|
||||
| main.rs:521:12:521:12 | n | Variable 'n' is not used. |
|
||||
| more.rs:24:9:24:11 | val | Variable 'val' is not used. |
|
||||
|
||||
@@ -518,7 +518,7 @@ fn macros4() {
|
||||
|
||||
fn macros5() {
|
||||
match std::env::args().nth(1).unwrap().parse::<u16>() {
|
||||
Ok(n) => { // $ SPURIOUS: Alert[rust/unused-variable]
|
||||
Ok(n) => {
|
||||
undefined_macro_call!(n);
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in New Issue
Block a user