summary refs log tree commit diff
path: root/tests/ui/drop/lint-if-let-rescope.fixed
blob: fec2e3b2ae7055993cc5b33a2689c1c31e3e603c (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//@ run-rustfix

#![deny(if_let_rescope)]
#![feature(stmt_expr_attributes)]
#![allow(irrefutable_let_patterns, unused_parens)]

fn droppy() -> Droppy {
    Droppy
}
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() {
        // Should not lint
    }

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

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

    if droppy().get().is_some() {
        // Should not lint
    } else { match droppy().get() { Some(_value) => {
        //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
        //~| WARN: this changes meaning in Rust 2024
        //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
    } _ => if droppy().get().is_none() {
        //~^ HELP: the value is now dropped here in Edition 2024
    }}}

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

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

    #[rustfmt::skip]
    if (match droppy().get() { Some(_value) => { true } _ => { false }}) {
        //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
        //~| WARN: this changes meaning in Rust 2024
        //~| HELP: the value is now dropped here in Edition 2024
        //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
        // do something
    } else if (((match droppy().get() { Some(_value) => { true } _ => { false }}))) {
        //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
        //~| WARN: this changes meaning in Rust 2024
        //~| HELP: the value is now dropped here in Edition 2024
        //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
    }

    while let Some(_value) = droppy().get() {
        // Should not lint
        break;
    }

    while (match droppy().get() { Some(_value) => { false } _ => { true }}) {
        //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
        //~| WARN: this changes meaning in Rust 2024
        //~| HELP: the value is now dropped here in Edition 2024
        //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
    }
}