File: lint-if-let-rescope-gated.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (33 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (4)
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
    }
}