2023-01-24 02:06:35 -06:00
|
|
|
//@ run-rustfix
|
|
|
|
|
|
|
|
#![deny(if_let_rescope)]
|
2024-10-20 16:06:30 -05:00
|
|
|
#![feature(stmt_expr_attributes)]
|
2024-09-29 14:40:48 -05:00
|
|
|
#![allow(irrefutable_let_patterns, unused_parens)]
|
2023-01-24 02:06:35 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
match droppy().get() { Some(_value) => {
|
2023-01-24 02:06:35 -06:00
|
|
|
//~^ 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
|
|
|
|
} _ => {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
|
|
|
// do something else
|
|
|
|
}}
|
2024-09-05 14:03:10 -05:00
|
|
|
|
|
|
|
match droppy().get() { Some(_value) => {
|
|
|
|
//~^ 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
|
|
|
|
} _ => { match droppy().get() { Some(_value) => {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
|
|
|
// 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 { match droppy().get() { Some(_value) => {
|
|
|
|
//~^ 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
|
|
|
} _ => if droppy().get().is_none() {
|
|
|
|
//~^ HELP: the value is now dropped here in Edition 2024
|
|
|
|
}}}
|
2023-01-24 02:06:35 -06:00
|
|
|
|
2024-09-05 14:03:10 -05:00
|
|
|
if let Some(1) = { match Droppy.get() { Some(_value) => { Some(1) } _ => { None }} } {
|
2023-01-24 02:06:35 -06:00
|
|
|
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
|
2024-09-05 14:03:10 -05:00
|
|
|
//~| WARN: this changes meaning in Rust 2024
|
2023-01-24 02:06:35 -06:00
|
|
|
//~| 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
|
|
|
}
|
|
|
|
|
2024-09-05 14:03:10 -05:00
|
|
|
if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } {
|
2023-01-24 02:06:35 -06:00
|
|
|
//~^ 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
|
|
|
}
|
2024-09-29 14:40:48 -05:00
|
|
|
|
2024-09-30 09:21:45 -05:00
|
|
|
#[rustfmt::skip]
|
2024-09-29 14:40:48 -05:00
|
|
|
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
|
2024-09-30 09:21:45 -05:00
|
|
|
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
|
2024-09-29 14:40:48 -05:00
|
|
|
// do something
|
2024-09-30 09:21:45 -05:00
|
|
|
} 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
|
2024-09-29 14:40:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while let Some(_value) = droppy().get() {
|
|
|
|
// Should not lint
|
|
|
|
break;
|
|
|
|
}
|
2024-09-30 09:21:45 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-01-24 02:06:35 -06:00
|
|
|
}
|