Skip to content

Commit db10b7f

Browse files
committed
removed gate and added test for drop order
1 parent d34eb45 commit db10b7f

12 files changed

+132
-67
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,31 +3407,19 @@ impl<'a> Parser<'a> {
34073407
fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<P<Expr>>> {
34083408
// Used to check the `if_let_guard` feature mostly by scanning
34093409
// `&&` tokens.
3410-
fn has_let_expr(expr: &Expr) -> bool {
3411-
match &expr.kind {
3412-
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, lhs, rhs) => {
3413-
let lhs_rslt = has_let_expr(lhs);
3414-
let rhs_rslt = has_let_expr(rhs);
3415-
lhs_rslt || rhs_rslt
3416-
}
3417-
ExprKind::Let(..) => true,
3418-
_ => false,
3419-
}
3420-
}
34213410
if !self.eat_keyword(exp!(If)) {
34223411
// No match arm guard present.
34233412
return Ok(None);
34243413
}
34253414

3426-
let if_span = self.prev_token.span;
34273415
let mut cond = self.parse_match_guard_condition()?;
34283416

3429-
CondChecker::new(self, LetChainsPolicy::AlwaysAllowed).visit_expr(&mut cond);
3417+
CondChecker::new(
3418+
self,
3419+
LetChainsPolicy::EditionDependent { current_edition: Edition::Edition2024 },
3420+
)
3421+
.visit_expr(&mut cond);
34303422

3431-
if has_let_expr(&cond) {
3432-
let span = if_span.to(cond.span);
3433-
self.psess.gated_spans.gate(sym::if_let_guard, span);
3434-
}
34353423
Ok(Some(cond))
34363424
}
34373425

tests/ui/drop/drop-order-comparisons.e2021.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,4 @@ impl<'b> Drop for LogDrop<'b> {
613613
fn drop(&mut self) {
614614
self.0.mark(self.1);
615615
}
616-
}
616+
}

tests/ui/drop/drop-order-comparisons.e2021.stderr

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ LL | | }, e.mark(3), e.ok(4));
2929
= warning: this changes meaning in Rust 2024
3030
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
3131
note: `#3` invokes this custom destructor
32-
--> $DIR/drop-order-comparisons.rs:612:1
32+
--> $DIR/drop-order-comparisons.rs:611:1
3333
|
3434
LL | impl<'b> Drop for LogDrop<'b> {
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636
note: `#1` invokes this custom destructor
37-
--> $DIR/drop-order-comparisons.rs:612:1
37+
--> $DIR/drop-order-comparisons.rs:611:1
3838
|
3939
LL | impl<'b> Drop for LogDrop<'b> {
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
note: `_v` invokes this custom destructor
42-
--> $DIR/drop-order-comparisons.rs:612:1
42+
--> $DIR/drop-order-comparisons.rs:611:1
4343
|
4444
LL | impl<'b> Drop for LogDrop<'b> {
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4646
note: `#2` invokes this custom destructor
47-
--> $DIR/drop-order-comparisons.rs:612:1
47+
--> $DIR/drop-order-comparisons.rs:611:1
4848
|
4949
LL | impl<'b> Drop for LogDrop<'b> {
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,12 +77,12 @@ LL | | }, e.mark(1), e.ok(4));
7777
= warning: this changes meaning in Rust 2024
7878
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
7979
note: `#2` invokes this custom destructor
80-
--> $DIR/drop-order-comparisons.rs:612:1
80+
--> $DIR/drop-order-comparisons.rs:611:1
8181
|
8282
LL | impl<'b> Drop for LogDrop<'b> {
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484
note: `#1` invokes this custom destructor
85-
--> $DIR/drop-order-comparisons.rs:612:1
85+
--> $DIR/drop-order-comparisons.rs:611:1
8686
|
8787
LL | impl<'b> Drop for LogDrop<'b> {
8888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -109,12 +109,12 @@ LL | | }, e.mark(1), e.ok(4));
109109
= warning: this changes meaning in Rust 2024
110110
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
111111
note: `#2` invokes this custom destructor
112-
--> $DIR/drop-order-comparisons.rs:612:1
112+
--> $DIR/drop-order-comparisons.rs:611:1
113113
|
114114
LL | impl<'b> Drop for LogDrop<'b> {
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116116
note: `#1` invokes this custom destructor
117-
--> $DIR/drop-order-comparisons.rs:612:1
117+
--> $DIR/drop-order-comparisons.rs:611:1
118118
|
119119
LL | impl<'b> Drop for LogDrop<'b> {
120120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -141,12 +141,12 @@ LL | | }, e.mark(2), e.ok(3));
141141
= warning: this changes meaning in Rust 2024
142142
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
143143
note: `#2` invokes this custom destructor
144-
--> $DIR/drop-order-comparisons.rs:612:1
144+
--> $DIR/drop-order-comparisons.rs:611:1
145145
|
146146
LL | impl<'b> Drop for LogDrop<'b> {
147147
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148148
note: `#1` invokes this custom destructor
149-
--> $DIR/drop-order-comparisons.rs:612:1
149+
--> $DIR/drop-order-comparisons.rs:611:1
150150
|
151151
LL | impl<'b> Drop for LogDrop<'b> {
152152
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -173,12 +173,12 @@ LL | | }, e.mark(2), e.ok(3));
173173
= warning: this changes meaning in Rust 2024
174174
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
175175
note: `#2` invokes this custom destructor
176-
--> $DIR/drop-order-comparisons.rs:612:1
176+
--> $DIR/drop-order-comparisons.rs:611:1
177177
|
178178
LL | impl<'b> Drop for LogDrop<'b> {
179179
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180180
note: `#1` invokes this custom destructor
181-
--> $DIR/drop-order-comparisons.rs:612:1
181+
--> $DIR/drop-order-comparisons.rs:611:1
182182
|
183183
LL | impl<'b> Drop for LogDrop<'b> {
184184
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -195,7 +195,7 @@ LL | _ = (if let Ok(_) = e.ok(4).as_ref() {
195195
= warning: this changes meaning in Rust 2024
196196
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
197197
note: value invokes this custom destructor
198-
--> $DIR/drop-order-comparisons.rs:612:1
198+
--> $DIR/drop-order-comparisons.rs:611:1
199199
|
200200
LL | impl<'b> Drop for LogDrop<'b> {
201201
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -225,7 +225,7 @@ LL | _ = (if let Ok(_) = e.err(4).as_ref() {} else {
225225
= warning: this changes meaning in Rust 2024
226226
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
227227
note: value invokes this custom destructor
228-
--> $DIR/drop-order-comparisons.rs:612:1
228+
--> $DIR/drop-order-comparisons.rs:611:1
229229
|
230230
LL | impl<'b> Drop for LogDrop<'b> {
231231
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -254,7 +254,7 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else {
254254
= warning: this changes meaning in Rust 2024
255255
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
256256
note: value invokes this custom destructor
257-
--> $DIR/drop-order-comparisons.rs:612:1
257+
--> $DIR/drop-order-comparisons.rs:611:1
258258
|
259259
LL | impl<'b> Drop for LogDrop<'b> {
260260
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -273,7 +273,7 @@ LL ~ }}
273273
|
274274

275275
warning: `if let` assigns a shorter lifetime since Edition 2024
276-
--> $DIR/drop-order-comparisons.rs:372:12
276+
--> $DIR/drop-order-comparisons.rs:371:12
277277
|
278278
LL | if let true = e.err(9).is_ok() {} else {
279279
| ^^^^^^^^^^^--------^^^^^^^^
@@ -283,12 +283,12 @@ LL | if let true = e.err(9).is_ok() {} else {
283283
= warning: this changes meaning in Rust 2024
284284
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
285285
note: value invokes this custom destructor
286-
--> $DIR/drop-order-comparisons.rs:612:1
286+
--> $DIR/drop-order-comparisons.rs:611:1
287287
|
288288
LL | impl<'b> Drop for LogDrop<'b> {
289289
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290290
help: the value is now dropped here in Edition 2024
291-
--> $DIR/drop-order-comparisons.rs:372:41
291+
--> $DIR/drop-order-comparisons.rs:371:41
292292
|
293293
LL | if let true = e.err(9).is_ok() {} else {
294294
| ^
@@ -302,7 +302,7 @@ LL ~ }}}}}}}}};
302302
|
303303

304304
warning: `if let` assigns a shorter lifetime since Edition 2024
305-
--> $DIR/drop-order-comparisons.rs:375:12
305+
--> $DIR/drop-order-comparisons.rs:374:12
306306
|
307307
LL | if let Ok(_v) = e.err(8) {} else {
308308
| ^^^^^^^^^^^^^--------
@@ -312,12 +312,12 @@ LL | if let Ok(_v) = e.err(8) {} else {
312312
= warning: this changes meaning in Rust 2024
313313
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
314314
note: value invokes this custom destructor
315-
--> $DIR/drop-order-comparisons.rs:612:1
315+
--> $DIR/drop-order-comparisons.rs:611:1
316316
|
317317
LL | impl<'b> Drop for LogDrop<'b> {
318318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
319319
help: the value is now dropped here in Edition 2024
320-
--> $DIR/drop-order-comparisons.rs:375:35
320+
--> $DIR/drop-order-comparisons.rs:374:35
321321
|
322322
LL | if let Ok(_v) = e.err(8) {} else {
323323
| ^
@@ -331,7 +331,7 @@ LL ~ }}}}}}}}};
331331
|
332332

333333
warning: `if let` assigns a shorter lifetime since Edition 2024
334-
--> $DIR/drop-order-comparisons.rs:378:12
334+
--> $DIR/drop-order-comparisons.rs:377:12
335335
|
336336
LL | if let Ok(_) = e.err(7) {} else {
337337
| ^^^^^^^^^^^^--------
@@ -341,12 +341,12 @@ LL | if let Ok(_) = e.err(7) {} else {
341341
= warning: this changes meaning in Rust 2024
342342
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
343343
note: value invokes this custom destructor
344-
--> $DIR/drop-order-comparisons.rs:612:1
344+
--> $DIR/drop-order-comparisons.rs:611:1
345345
|
346346
LL | impl<'b> Drop for LogDrop<'b> {
347347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
348348
help: the value is now dropped here in Edition 2024
349-
--> $DIR/drop-order-comparisons.rs:378:34
349+
--> $DIR/drop-order-comparisons.rs:377:34
350350
|
351351
LL | if let Ok(_) = e.err(7) {} else {
352352
| ^
@@ -360,7 +360,7 @@ LL ~ }}}}}}}}};
360360
|
361361

362362
warning: `if let` assigns a shorter lifetime since Edition 2024
363-
--> $DIR/drop-order-comparisons.rs:381:12
363+
--> $DIR/drop-order-comparisons.rs:380:12
364364
|
365365
LL | if let Ok(_) = e.err(6).as_ref() {} else {
366366
| ^^^^^^^^^^^^--------^^^^^^^^^
@@ -370,12 +370,12 @@ LL | if let Ok(_) = e.err(6).as_ref() {} else {
370370
= warning: this changes meaning in Rust 2024
371371
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
372372
note: value invokes this custom destructor
373-
--> $DIR/drop-order-comparisons.rs:612:1
373+
--> $DIR/drop-order-comparisons.rs:611:1
374374
|
375375
LL | impl<'b> Drop for LogDrop<'b> {
376376
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
377377
help: the value is now dropped here in Edition 2024
378-
--> $DIR/drop-order-comparisons.rs:381:43
378+
--> $DIR/drop-order-comparisons.rs:380:43
379379
|
380380
LL | if let Ok(_) = e.err(6).as_ref() {} else {
381381
| ^
@@ -389,7 +389,7 @@ LL ~ }}}}}}}}};
389389
|
390390

391391
warning: `if let` assigns a shorter lifetime since Edition 2024
392-
--> $DIR/drop-order-comparisons.rs:385:12
392+
--> $DIR/drop-order-comparisons.rs:384:12
393393
|
394394
LL | if let Ok(_v) = e.err(5) {} else {
395395
| ^^^^^^^^^^^^^--------
@@ -399,12 +399,12 @@ LL | if let Ok(_v) = e.err(5) {} else {
399399
= warning: this changes meaning in Rust 2024
400400
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
401401
note: value invokes this custom destructor
402-
--> $DIR/drop-order-comparisons.rs:612:1
402+
--> $DIR/drop-order-comparisons.rs:611:1
403403
|
404404
LL | impl<'b> Drop for LogDrop<'b> {
405405
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
406406
help: the value is now dropped here in Edition 2024
407-
--> $DIR/drop-order-comparisons.rs:385:35
407+
--> $DIR/drop-order-comparisons.rs:384:35
408408
|
409409
LL | if let Ok(_v) = e.err(5) {} else {
410410
| ^
@@ -418,7 +418,7 @@ LL ~ }}}}}}}}};
418418
|
419419

420420
warning: `if let` assigns a shorter lifetime since Edition 2024
421-
--> $DIR/drop-order-comparisons.rs:388:12
421+
--> $DIR/drop-order-comparisons.rs:387:12
422422
|
423423
LL | if let Ok(_) = e.err(4) {} else {
424424
| ^^^^^^^^^^^^--------
@@ -428,12 +428,12 @@ LL | if let Ok(_) = e.err(4) {} else {
428428
= warning: this changes meaning in Rust 2024
429429
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
430430
note: value invokes this custom destructor
431-
--> $DIR/drop-order-comparisons.rs:612:1
431+
--> $DIR/drop-order-comparisons.rs:611:1
432432
|
433433
LL | impl<'b> Drop for LogDrop<'b> {
434434
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
435435
help: the value is now dropped here in Edition 2024
436-
--> $DIR/drop-order-comparisons.rs:388:34
436+
--> $DIR/drop-order-comparisons.rs:387:34
437437
|
438438
LL | if let Ok(_) = e.err(4) {} else {
439439
| ^
@@ -447,7 +447,7 @@ LL ~ }}}}}}}}};
447447
|
448448

449449
warning: `if let` assigns a shorter lifetime since Edition 2024
450-
--> $DIR/drop-order-comparisons.rs:424:12
450+
--> $DIR/drop-order-comparisons.rs:423:12
451451
|
452452
LL | if let Ok(_) = e.err(4).as_ref() {} else {
453453
| ^^^^^^^^^^^^--------^^^^^^^^^
@@ -457,12 +457,12 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else {
457457
= warning: this changes meaning in Rust 2024
458458
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
459459
note: value invokes this custom destructor
460-
--> $DIR/drop-order-comparisons.rs:612:1
460+
--> $DIR/drop-order-comparisons.rs:611:1
461461
|
462462
LL | impl<'b> Drop for LogDrop<'b> {
463463
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
464464
help: the value is now dropped here in Edition 2024
465-
--> $DIR/drop-order-comparisons.rs:424:43
465+
--> $DIR/drop-order-comparisons.rs:423:43
466466
|
467467
LL | if let Ok(_) = e.err(4).as_ref() {} else {
468468
| ^

tests/ui/drop/drop-order-comparisons.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,4 @@ impl<'b> Drop for LogDrop<'b> {
613613
fn drop(&mut self) {
614614
self.0.mark(self.1);
615615
}
616-
}
616+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//@ run-pass
2+
//@revisions: edition2015 edition2018 edition2021 edition2024
3+
//@[edition2015] edition:2015
4+
//@[edition2018] edition:2018
5+
//@[edition2021] edition:2021
6+
//@[edition2024] edition:2024
7+
8+
#![allow(irrefutable_let_patterns)]
9+
10+
use std::sync::Mutex;
11+
12+
static A: Mutex<Vec<i32>> = Mutex::new(Vec::new());
13+
14+
struct D(i32);
15+
16+
fn make_d(x: i32) -> D {
17+
A.lock().unwrap().push(x);
18+
D(x)
19+
}
20+
21+
impl Drop for D {
22+
fn drop(&mut self) {
23+
A.lock().unwrap().push(!self.0);
24+
}
25+
}
26+
27+
fn if_let_guard(num: i32) {
28+
let _d = make_d(1);
29+
match num {
30+
1 | 2 if let D(ref _x) = make_d(2) => {
31+
make_d(3);
32+
}
33+
_ => {}
34+
}
35+
}
36+
37+
fn if_let(num: i32) {
38+
let _d = make_d(1);
39+
match num {
40+
1 | 2 => {
41+
if let D(ref _x) = make_d(2) {
42+
make_d(3);
43+
}
44+
}
45+
_ => {}
46+
}
47+
}
48+
49+
fn main() {
50+
if_let(1);
51+
if_let(2);
52+
if_let_guard(1);
53+
if_let_guard(2);
54+
let expected =
55+
[1, 2, 3, !3, !2, !1, 1, 2, 3, !3, !2, !1,
56+
// Here is two parts, first one is for basic if let inside the match arm
57+
// And second part is for if let guard
58+
1, 2, 3, !3, !2, !1, 1, 2, 3, !3, !2, !1];
59+
assert_eq!(*A.lock().unwrap(), expected);
60+
}

0 commit comments

Comments
 (0)