1
Fork 0

apply suggestions

This commit is contained in:
Ding Xiang Fei 2024-09-30 22:21:45 +08:00
parent 6d1a25ad7e
commit ed5443fcdf
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
4 changed files with 75 additions and 8 deletions

View file

@ -260,7 +260,8 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
// if let .. { body } else { break; } // 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. // means nothing substantial to this `while` statement.
self.skip.insert(value.hir_id); self.skip.insert(value.hir_id);
return; return;

View file

@ -1,7 +1,7 @@
//@ run-rustfix //@ run-rustfix
#![deny(if_let_rescope)] #![deny(if_let_rescope)]
#![feature(if_let_rescope)] #![feature(if_let_rescope, stmt_expr_attributes)]
#![allow(irrefutable_let_patterns, unused_parens)] #![allow(irrefutable_let_patterns, unused_parens)]
fn droppy() -> Droppy { 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 //~| 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 }}) { if (match droppy().get() { Some(_value) => { true } _ => { false }}) {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 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: 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 // 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() { while let Some(_value) = droppy().get() {
// Should not lint // Should not lint
break; 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
}
} }

View file

@ -1,7 +1,7 @@
//@ run-rustfix //@ run-rustfix
#![deny(if_let_rescope)] #![deny(if_let_rescope)]
#![feature(if_let_rescope)] #![feature(if_let_rescope, stmt_expr_attributes)]
#![allow(irrefutable_let_patterns, unused_parens)] #![allow(irrefutable_let_patterns, unused_parens)]
fn droppy() -> Droppy { 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 //~| 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 }) { if (if let Some(_value) = droppy().get() { true } else { false }) {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 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: 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 // 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() { while let Some(_value) = droppy().get() {
// Should not lint // Should not lint
break; 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
}
} }

View file

@ -132,7 +132,7 @@ LL | if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } {
| ~~~~~ +++++++++++++++++ ++++++++ | ~~~~~ +++++++++++++++++ ++++++++
error: `if let` assigns a shorter lifetime since Edition 2024 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 }) { 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 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = 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 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 }) { 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 }}) { 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