about summary refs log tree commit diff
path: root/tests/ui/drop/lint-if-let-rescope-gated.rs
blob: f5538a37eef85bbda9090392784418c49df303e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// This test checks that the lint `if_let_rescope` only actions
// when Edition 2021 or prior is targeted here because the lint should work especially
// when edition migration towards 2024 is executed.

//@ revisions: edition2021 edition2024
//@ [edition2021] edition: 2021
//@ [edition2024] edition: 2024
//@ [edition2024] check-pass

#![deny(if_let_rescope)]
#![allow(irrefutable_let_patterns)]

struct Droppy;
impl Drop for Droppy {
    fn drop(&mut self) {
        println!("dropped");
    }
}
impl Droppy {
    fn get(&self) -> Option<u8> {
        None
    }
}

fn main() {
    if let Some(_value) = Droppy.get() {
        //[edition2021]~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
        //[edition2021]~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
        //[edition2021]~| WARN: this changes meaning in Rust 2024
    } else {
        //[edition2021]~^ HELP: the value is now dropped here in Edition 2024
    }
}