Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `rust/unused-variable` query no longer reports variables in functions containing the standard `todo!()` or `unimplemented!()` macros.
9 changes: 7 additions & 2 deletions rust/ql/src/queries/unusedentities/UnusedVariable.qll
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import rust
private import codeql.rust.internal.PathResolution

/**
* A deliberately unused variable, for example `_` or `_x`.
Expand All@@ -23,9 +24,13 @@ predicate isUnused(Variable v) {
*/
class IncompleteCallable extends Callable {
IncompleteCallable() {
exists(MacroExpr me |
me.getEnclosingCallable() = this and
exists(MacroExpr me | me.getEnclosingCallable() = this |
not me.getMacroCall().hasMacroCallExpansion()
or
exists(ItemNode i |
i.getCanonicalPath(_) = ["core::macros::unimplemented", "core::macros::todo"] and
me.getMacroCall().resolveMacro() = i
)
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions rust/ql/test/query-tests/unusedentities/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -558,6 +558,14 @@ trait MyTrait {
fn my_func2(&self, x: i32) -> i32;
}

fn unimplemented(x : i32) {
unimplemented!()
}

fn todo(x : i32) {
todo!()
}

// --- main ---

fn main() {
Expand Down
Loading