2023-01-24 02:06:35 -06:00
|
|
|
//@ run-rustfix
|
|
|
|
|
|
|
|
#![deny(if_let_rescope)]
|
2024-09-05 14:03:10 -05:00
|
|
|
#![feature(if_let_rescope)]
|
2023-01-24 02:06:35 -06:00
|
|
|
#![allow(irrefutable_let_patterns)]
|
|
|
|
|
|
|
|
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() {
|
2024-09-05 14:03:10 -05:00
|
|
|
if let Some(_value) = droppy().get() {
|
|
|
|
// Should not lint
|
|
|
|
}
|
|
|
|
|
2023-01-24 02:06:35 -06:00
|
|
|
if let Some(_value) = droppy().get() {
|
|
|
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
|
|
|
//~| WARN: this changes meaning in Rust 2024
|
2024-09-12 13:43:49 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2023-01-24 02:06:35 -06:00
|
|
|
// do something
|
|
|
|
} else {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
2024-09-05 14:03:10 -05:00
|
|
|
// do something else
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(_value) = droppy().get() {
|
|
|
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
|
|
|
//~| WARN: this changes meaning in Rust 2024
|
2024-09-12 13:43:49 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2024-09-05 14:03:10 -05:00
|
|
|
// do something
|
|
|
|
} else if let Some(_value) = droppy().get() {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
2023-01-24 02:06:35 -06:00
|
|
|
// do something else
|
|
|
|
}
|
2024-09-12 13:43:49 -05:00
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
2024-09-05 14:03:10 -05:00
|
|
|
|
|
|
|
if droppy().get().is_some() {
|
|
|
|
// Should not lint
|
|
|
|
} else if let Some(_value) = droppy().get() {
|
|
|
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
|
|
|
//~| WARN: this changes meaning in Rust 2024
|
2024-09-12 13:43:49 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2024-09-05 14:03:10 -05:00
|
|
|
} else if droppy().get().is_none() {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
|
|
|
}
|
2023-01-24 02:06:35 -06:00
|
|
|
|
|
|
|
if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { 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
|
2024-09-12 13:43:49 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2023-01-24 02:06:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if let () = { if let Some(_value) = Droppy.get() {} } {
|
|
|
|
//~^ 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
|
2024-09-12 13:43:49 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2023-01-24 02:06:35 -06:00
|
|
|
}
|
|
|
|
}
|