Auto merge of #77274 - tmiasko:liveness-cnd, r=lcnr
Liveness refactoring continued * Move body_owner field from IrMaps to Liveness (the only user of the field). * Use upvars instead of FnKind to check for closures (avoids FnKind, will be useful when checking all bodies, not just fns). * Use visit_param to add variables corresponding to params. * Store upvars_mentioned inside Liveness struct. * Inline visitor implementation for IrMaps, avoiding unnecessary indirection. * Test interaction with automatically_derived attribute (not covered by any of existing tests). No functional changes intended.
This commit is contained in:
commit
381b445ff5
3 changed files with 245 additions and 219 deletions
38
src/test/ui/liveness/liveness-derive.rs
Normal file
38
src/test/ui/liveness/liveness-derive.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Test for interaction between #[automatically_derived] attribute used by
|
||||
// built-in derives and lints generated by liveness pass.
|
||||
//
|
||||
// edition:2018
|
||||
// check-pass
|
||||
#![warn(unused)]
|
||||
|
||||
pub trait T: Sized {
|
||||
const N: usize;
|
||||
fn t(&self) -> Self;
|
||||
}
|
||||
|
||||
impl T for u32 {
|
||||
const N: usize = {
|
||||
let a = 0; // FIXME should warn about unused variable
|
||||
4
|
||||
};
|
||||
|
||||
fn t(&self) -> Self {
|
||||
let b = 16; //~ WARN unused variable: `b`
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl T for i32 {
|
||||
const N: usize = {
|
||||
let c = 0;
|
||||
4
|
||||
};
|
||||
|
||||
fn t(&self) -> Self {
|
||||
let d = 17;
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/liveness/liveness-derive.stderr
Normal file
15
src/test/ui/liveness/liveness-derive.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
warning: unused variable: `b`
|
||||
--> $DIR/liveness-derive.rs:20:13
|
||||
|
|
||||
LL | let b = 16;
|
||||
| ^ help: if this is intentional, prefix it with an underscore: `_b`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/liveness-derive.rs:6:9
|
||||
|
|
||||
LL | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue