Lint dead code in closures
This commit is contained in:
parent
bda32a4023
commit
c7a4f387fd
3 changed files with 39 additions and 0 deletions
|
@ -395,6 +395,9 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
||||||
self.mark_as_used_if_union(*adt, fields);
|
self.mark_as_used_if_union(*adt, fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hir::ExprKind::Closure(cls) => {
|
||||||
|
self.insert_def_id(cls.def_id.to_def_id());
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
tests/ui/lint/dead-code/in-closure.rs
Normal file
16
tests/ui/lint/dead-code/in-closure.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// edition: 2021
|
||||||
|
|
||||||
|
#![deny(dead_code)]
|
||||||
|
|
||||||
|
pub fn foo() {
|
||||||
|
let closure = || {
|
||||||
|
fn a() {} //~ ERROR function `a` is never used
|
||||||
|
};
|
||||||
|
closure()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn async_foo() {
|
||||||
|
const A: usize = 1; //~ ERROR constant `A` is never used
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
20
tests/ui/lint/dead-code/in-closure.stderr
Normal file
20
tests/ui/lint/dead-code/in-closure.stderr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
error: function `a` is never used
|
||||||
|
--> $DIR/in-closure.rs:7:12
|
||||||
|
|
|
||||||
|
LL | fn a() {}
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/in-closure.rs:3:9
|
||||||
|
|
|
||||||
|
LL | #![deny(dead_code)]
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
||||||
|
error: constant `A` is never used
|
||||||
|
--> $DIR/in-closure.rs:13:11
|
||||||
|
|
|
||||||
|
LL | const A: usize = 1;
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue