Skip to content

Commit ed5443f

Browse files
apply suggestions
1 parent 6d1a25a commit ed5443f

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

Diff for: compiler/rustc_lint/src/if_let_rescope.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
260260
// if let .. { body } else { break; }
261261
// }
262262
// ```
263-
// There is no observable from the `{ break; }` block so the edition change
263+
// There is no observable change in drop order on the overall `if let` expression
264+
// given that the `{ break; }` block is trivial so the edition change
264265
// means nothing substantial to this `while` statement.
265266
self.skip.insert(value.hir_id);
266267
return;

Diff for: tests/ui/drop/lint-if-let-rescope.fixed

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-rustfix
22

33
#![deny(if_let_rescope)]
4-
#![feature(if_let_rescope)]
4+
#![feature(if_let_rescope, stmt_expr_attributes)]
55
#![allow(irrefutable_let_patterns, unused_parens)]
66

77
fn droppy() -> Droppy {
@@ -69,16 +69,29 @@ fn main() {
6969
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7070
}
7171

72+
#[rustfmt::skip]
7273
if (match droppy().get() { Some(_value) => { true } _ => { false }}) {
7374
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
7475
//~| WARN: this changes meaning in Rust 2024
75-
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7676
//~| HELP: the value is now dropped here in Edition 2024
77+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7778
// do something
79+
} else if (((match droppy().get() { Some(_value) => { true } _ => { false }}))) {
80+
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
81+
//~| WARN: this changes meaning in Rust 2024
82+
//~| HELP: the value is now dropped here in Edition 2024
83+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7884
}
7985

8086
while let Some(_value) = droppy().get() {
8187
// Should not lint
8288
break;
8389
}
90+
91+
while (match droppy().get() { Some(_value) => { false } _ => { true }}) {
92+
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
93+
//~| WARN: this changes meaning in Rust 2024
94+
//~| HELP: the value is now dropped here in Edition 2024
95+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
96+
}
8497
}

Diff for: tests/ui/drop/lint-if-let-rescope.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-rustfix
22

33
#![deny(if_let_rescope)]
4-
#![feature(if_let_rescope)]
4+
#![feature(if_let_rescope, stmt_expr_attributes)]
55
#![allow(irrefutable_let_patterns, unused_parens)]
66

77
fn droppy() -> Droppy {
@@ -69,16 +69,29 @@ fn main() {
6969
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7070
}
7171

72+
#[rustfmt::skip]
7273
if (if let Some(_value) = droppy().get() { true } else { false }) {
7374
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
7475
//~| WARN: this changes meaning in Rust 2024
75-
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7676
//~| HELP: the value is now dropped here in Edition 2024
77+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7778
// do something
79+
} else if (((if let Some(_value) = droppy().get() { true } else { false }))) {
80+
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
81+
//~| WARN: this changes meaning in Rust 2024
82+
//~| HELP: the value is now dropped here in Edition 2024
83+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
7884
}
7985

8086
while let Some(_value) = droppy().get() {
8187
// Should not lint
8288
break;
8389
}
90+
91+
while (if let Some(_value) = droppy().get() { false } else { true }) {
92+
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
93+
//~| WARN: this changes meaning in Rust 2024
94+
//~| HELP: the value is now dropped here in Edition 2024
95+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
96+
}
8497
}

Diff for: tests/ui/drop/lint-if-let-rescope.stderr

+43-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ LL | if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } {
132132
| ~~~~~ +++++++++++++++++ ++++++++
133133

134134
error: `if let` assigns a shorter lifetime since Edition 2024
135-
--> $DIR/lint-if-let-rescope.rs:72:12
135+
--> $DIR/lint-if-let-rescope.rs:73:12
136136
|
137137
LL | if (if let Some(_value) = droppy().get() { true } else { false }) {
138138
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^
@@ -142,7 +142,7 @@ LL | if (if let Some(_value) = droppy().get() { true } else { false }) {
142142
= warning: this changes meaning in Rust 2024
143143
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
144144
help: the value is now dropped here in Edition 2024
145-
--> $DIR/lint-if-let-rescope.rs:72:53
145+
--> $DIR/lint-if-let-rescope.rs:73:53
146146
|
147147
LL | if (if let Some(_value) = droppy().get() { true } else { false }) {
148148
| ^
@@ -151,5 +151,45 @@ help: a `match` with a single arm can preserve the drop order up to Edition 2021
151151
LL | if (match droppy().get() { Some(_value) => { true } _ => { false }}) {
152152
| ~~~~~ +++++++++++++++++ ~~~~ +
153153

154-
error: aborting due to 6 previous errors
154+
error: `if let` assigns a shorter lifetime since Edition 2024
155+
--> $DIR/lint-if-let-rescope.rs:79:21
156+
|
157+
LL | } else if (((if let Some(_value) = droppy().get() { true } else { false }))) {
158+
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^
159+
| |
160+
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
161+
|
162+
= warning: this changes meaning in Rust 2024
163+
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
164+
help: the value is now dropped here in Edition 2024
165+
--> $DIR/lint-if-let-rescope.rs:79:62
166+
|
167+
LL | } else if (((if let Some(_value) = droppy().get() { true } else { false }))) {
168+
| ^
169+
help: a `match` with a single arm can preserve the drop order up to Edition 2021
170+
|
171+
LL | } else if (((match droppy().get() { Some(_value) => { true } _ => { false }}))) {
172+
| ~~~~~ +++++++++++++++++ ~~~~ +
173+
174+
error: `if let` assigns a shorter lifetime since Edition 2024
175+
--> $DIR/lint-if-let-rescope.rs:91:15
176+
|
177+
LL | while (if let Some(_value) = droppy().get() { false } else { true }) {
178+
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^
179+
| |
180+
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
181+
|
182+
= warning: this changes meaning in Rust 2024
183+
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
184+
help: the value is now dropped here in Edition 2024
185+
--> $DIR/lint-if-let-rescope.rs:91:57
186+
|
187+
LL | while (if let Some(_value) = droppy().get() { false } else { true }) {
188+
| ^
189+
help: a `match` with a single arm can preserve the drop order up to Edition 2021
190+
|
191+
LL | while (match droppy().get() { Some(_value) => { false } _ => { true }}) {
192+
| ~~~~~ +++++++++++++++++ ~~~~ +
193+
194+
error: aborting due to 8 previous errors
155195

0 commit comments

Comments
 (0)