Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Sep 30, 2024
1 parent 6d1a25a commit ed5443f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions tests/ui/drop/lint-if-let-rescope.fixed
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
}
17 changes: 15 additions & 2 deletions tests/ui/drop/lint-if-let-rescope.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
}
46 changes: 43 additions & 3 deletions tests/ui/drop/lint-if-let-rescope.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/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 }) {
| ^
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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

0 comments on commit ed5443f

Please sign in to comment.