diff --git a/compiler/rustc_lint/src/if_let_rescope.rs b/compiler/rustc_lint/src/if_let_rescope.rs index 8cb63d5cb0542..8f643de836a02 100644 --- a/compiler/rustc_lint/src/if_let_rescope.rs +++ b/compiler/rustc_lint/src/if_let_rescope.rs @@ -260,7 +260,8 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope { // if let .. { body } else { break; } // } // ``` - // There is no observable from the `{ break; }` block so the edition change + // There is no observable change in drop order on the overall `if let` expression + // given that the `{ break; }` block is trivial so the edition change // means nothing substantial to this `while` statement. self.skip.insert(value.hir_id); return; diff --git a/tests/ui/drop/lint-if-let-rescope.fixed b/tests/ui/drop/lint-if-let-rescope.fixed index d579ce9823691..199068d0fd265 100644 --- a/tests/ui/drop/lint-if-let-rescope.fixed +++ b/tests/ui/drop/lint-if-let-rescope.fixed @@ -1,7 +1,7 @@ //@ run-rustfix #![deny(if_let_rescope)] -#![feature(if_let_rescope)] +#![feature(if_let_rescope, stmt_expr_attributes)] #![allow(irrefutable_let_patterns, unused_parens)] fn droppy() -> Droppy { @@ -69,16 +69,29 @@ fn main() { //~| 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: a `match` with a single arm can preserve the drop order up to Edition 2021 //~| 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 + } } diff --git a/tests/ui/drop/lint-if-let-rescope.rs b/tests/ui/drop/lint-if-let-rescope.rs index aab293cdcfc77..4c043c0266cc4 100644 --- a/tests/ui/drop/lint-if-let-rescope.rs +++ b/tests/ui/drop/lint-if-let-rescope.rs @@ -1,7 +1,7 @@ //@ run-rustfix #![deny(if_let_rescope)] -#![feature(if_let_rescope)] +#![feature(if_let_rescope, stmt_expr_attributes)] #![allow(irrefutable_let_patterns, unused_parens)] fn droppy() -> Droppy { @@ -69,16 +69,29 @@ fn main() { //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021 } + #[rustfmt::skip] if (if let Some(_value) = droppy().get() { true } else { false }) { //~^ 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 //~| 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 (((if let Some(_value) = droppy().get() { true } else { 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 (if let Some(_value) = droppy().get() { false } else { 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 + } } diff --git a/tests/ui/drop/lint-if-let-rescope.stderr b/tests/ui/drop/lint-if-let-rescope.stderr index 50801ae166ff0..ef60d141b7988 100644 --- a/tests/ui/drop/lint-if-let-rescope.stderr +++ b/tests/ui/drop/lint-if-let-rescope.stderr @@ -132,7 +132,7 @@ LL | if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } { | ~~~~~ +++++++++++++++++ ++++++++ error: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/lint-if-let-rescope.rs:72:12 + --> $DIR/lint-if-let-rescope.rs:73:12 | LL | if (if let Some(_value) = droppy().get() { true } else { false }) { | ^^^^^^^^^^^^^^^^^^^--------^^^^^^ @@ -142,7 +142,7 @@ LL | if (if let Some(_value) = droppy().get() { true } else { false }) { = warning: this changes meaning in Rust 2024 = note: for more information, see issue #124085 help: the value is now dropped here in Edition 2024 - --> $DIR/lint-if-let-rescope.rs:72:53 + --> $DIR/lint-if-let-rescope.rs:73:53 | LL | if (if let Some(_value) = droppy().get() { true } else { false }) { | ^ @@ -151,5 +151,45 @@ help: a `match` with a single arm can preserve the drop order up to Edition 2021 LL | if (match droppy().get() { Some(_value) => { true } _ => { false }}) { | ~~~~~ +++++++++++++++++ ~~~~ + -error: aborting due to 6 previous errors +error: `if let` assigns a shorter lifetime since Edition 2024 + --> $DIR/lint-if-let-rescope.rs:79:21 + | +LL | } else if (((if let Some(_value) = droppy().get() { true } else { false }))) { + | ^^^^^^^^^^^^^^^^^^^--------^^^^^^ + | | + | this value has a significant drop implementation which may observe a major change in drop order and requires your discretion + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see issue #124085 +help: the value is now dropped here in Edition 2024 + --> $DIR/lint-if-let-rescope.rs:79:62 + | +LL | } else if (((if let Some(_value) = droppy().get() { true } else { false }))) { + | ^ +help: a `match` with a single arm can preserve the drop order up to Edition 2021 + | +LL | } else if (((match droppy().get() { Some(_value) => { true } _ => { false }}))) { + | ~~~~~ +++++++++++++++++ ~~~~ + + +error: `if let` assigns a shorter lifetime since Edition 2024 + --> $DIR/lint-if-let-rescope.rs:91:15 + | +LL | while (if let Some(_value) = droppy().get() { false } else { true }) { + | ^^^^^^^^^^^^^^^^^^^--------^^^^^^ + | | + | this value has a significant drop implementation which may observe a major change in drop order and requires your discretion + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see issue #124085 +help: the value is now dropped here in Edition 2024 + --> $DIR/lint-if-let-rescope.rs:91:57 + | +LL | while (if let Some(_value) = droppy().get() { false } else { true }) { + | ^ +help: a `match` with a single arm can preserve the drop order up to Edition 2021 + | +LL | while (match droppy().get() { Some(_value) => { false } _ => { true }}) { + | ~~~~~ +++++++++++++++++ ~~~~ + + +error: aborting due to 8 previous errors