rust/tests/ui/drop/lint-if-let-rescope-gated.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1.0 KiB
Rust
Raw Permalink Normal View History

// This test checks that the lint `if_let_rescope` only actions
2024-10-20 16:06:30 -05:00
// when Edition 2021 or prior is targeted here because the lint should work especially
// when edition migration towards 2024 is executed.
2024-10-20 16:06:30 -05:00
//@ revisions: edition2021 edition2024
//@ [edition2021] edition: 2021
//@ [edition2024] edition: 2024
//@ [edition2024] compile-flags: -Zunstable-options
//@ [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() {
2024-10-20 16:06:30 -05:00
//[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 {
2024-10-20 16:06:30 -05:00
//[edition2021]~^ HELP: the value is now dropped here in Edition 2024
}
}