Skip to content

Commit d2cc457

Browse files
committed
revert ability use let chains in if let guard, fixed tests
1 parent d6688ef commit d2cc457

File tree

9 files changed

+118
-35
lines changed

9 files changed

+118
-35
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,11 +3414,7 @@ impl<'a> Parser<'a> {
34143414

34153415
let mut cond = self.parse_match_guard_condition()?;
34163416

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

34233419
Ok(Some(cond))
34243420
}
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,82 @@
11
error: cannot borrow value as mutable more than once at a time
2-
--> $DIR/conflicting_bindings.rs:5:9
2+
--> $DIR/conflicting_bindings.rs:9:9
33
|
44
LL | let ref mut y @ ref mut z = x;
55
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
66
| |
77
| value is mutably borrowed by `y` here
88

99
error: cannot borrow value as mutable more than once at a time
10-
--> $DIR/conflicting_bindings.rs:7:14
10+
--> $DIR/conflicting_bindings.rs:11:14
1111
|
1212
LL | let Some(ref mut y @ ref mut z) = x else { return };
1313
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
1414
| |
1515
| value is mutably borrowed by `y` here
1616

1717
error: cannot borrow value as mutable more than once at a time
18-
--> $DIR/conflicting_bindings.rs:9:17
18+
--> $DIR/conflicting_bindings.rs:13:17
1919
|
2020
LL | if let Some(ref mut y @ ref mut z) = x {}
2121
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
2222
| |
2323
| value is mutably borrowed by `y` here
2424

2525
error: cannot borrow value as mutable more than once at a time
26-
--> $DIR/conflicting_bindings.rs:11:17
26+
--> $DIR/conflicting_bindings.rs:15:17
2727
|
2828
LL | if let Some(ref mut y @ ref mut z) = x && true {}
2929
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
3030
| |
3131
| value is mutably borrowed by `y` here
3232

3333
error: cannot borrow value as mutable more than once at a time
34-
--> $DIR/conflicting_bindings.rs:13:43
34+
--> $DIR/conflicting_bindings.rs:17:43
3535
|
3636
LL | if let Some(_) = Some(()) && let Some(ref mut y @ ref mut z) = x && true {}
3737
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
3838
| |
3939
| value is mutably borrowed by `y` here
4040

4141
error: cannot borrow value as mutable more than once at a time
42-
--> $DIR/conflicting_bindings.rs:15:20
42+
--> $DIR/conflicting_bindings.rs:19:20
4343
|
4444
LL | while let Some(ref mut y @ ref mut z) = x {}
4545
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
4646
| |
4747
| value is mutably borrowed by `y` here
4848

4949
error: cannot borrow value as mutable more than once at a time
50-
--> $DIR/conflicting_bindings.rs:17:20
50+
--> $DIR/conflicting_bindings.rs:21:20
5151
|
5252
LL | while let Some(ref mut y @ ref mut z) = x && true {}
5353
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
5454
| |
5555
| value is mutably borrowed by `y` here
5656

5757
error: cannot borrow value as mutable more than once at a time
58-
--> $DIR/conflicting_bindings.rs:20:9
58+
--> $DIR/conflicting_bindings.rs:24:9
5959
|
6060
LL | ref mut y @ ref mut z => {}
6161
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
6262
| |
6363
| value is mutably borrowed by `y` here
6464

6565
error: cannot borrow value as mutable more than once at a time
66-
--> $DIR/conflicting_bindings.rs:23:24
66+
--> $DIR/conflicting_bindings.rs:27:24
6767
|
6868
LL | () if let Some(ref mut y @ ref mut z) = x => {}
6969
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
7070
| |
7171
| value is mutably borrowed by `y` here
7272

73-
error: aborting due to 9 previous errors
73+
error: cannot borrow value as mutable more than once at a time
74+
--> $DIR/conflicting_bindings.rs:31:51
75+
|
76+
LL | () if let Some(()) = Some(()) && let Some(ref mut y @ ref mut z) = x && true => {}
77+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
78+
| |
79+
| value is mutably borrowed by `y` here
80+
81+
error: aborting due to 10 previous errors
7482

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
error: cannot borrow value as mutable more than once at a time
2+
--> $DIR/conflicting_bindings.rs:9:9
3+
|
4+
LL | let ref mut y @ ref mut z = x;
5+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
6+
| |
7+
| value is mutably borrowed by `y` here
8+
9+
error: cannot borrow value as mutable more than once at a time
10+
--> $DIR/conflicting_bindings.rs:11:14
11+
|
12+
LL | let Some(ref mut y @ ref mut z) = x else { return };
13+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
14+
| |
15+
| value is mutably borrowed by `y` here
16+
17+
error: cannot borrow value as mutable more than once at a time
18+
--> $DIR/conflicting_bindings.rs:13:17
19+
|
20+
LL | if let Some(ref mut y @ ref mut z) = x {}
21+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
22+
| |
23+
| value is mutably borrowed by `y` here
24+
25+
error: cannot borrow value as mutable more than once at a time
26+
--> $DIR/conflicting_bindings.rs:15:17
27+
|
28+
LL | if let Some(ref mut y @ ref mut z) = x && true {}
29+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
30+
| |
31+
| value is mutably borrowed by `y` here
32+
33+
error: cannot borrow value as mutable more than once at a time
34+
--> $DIR/conflicting_bindings.rs:17:43
35+
|
36+
LL | if let Some(_) = Some(()) && let Some(ref mut y @ ref mut z) = x && true {}
37+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
38+
| |
39+
| value is mutably borrowed by `y` here
40+
41+
error: cannot borrow value as mutable more than once at a time
42+
--> $DIR/conflicting_bindings.rs:19:20
43+
|
44+
LL | while let Some(ref mut y @ ref mut z) = x {}
45+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
46+
| |
47+
| value is mutably borrowed by `y` here
48+
49+
error: cannot borrow value as mutable more than once at a time
50+
--> $DIR/conflicting_bindings.rs:21:20
51+
|
52+
LL | while let Some(ref mut y @ ref mut z) = x && true {}
53+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
54+
| |
55+
| value is mutably borrowed by `y` here
56+
57+
error: cannot borrow value as mutable more than once at a time
58+
--> $DIR/conflicting_bindings.rs:24:9
59+
|
60+
LL | ref mut y @ ref mut z => {}
61+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
62+
| |
63+
| value is mutably borrowed by `y` here
64+
65+
error: cannot borrow value as mutable more than once at a time
66+
--> $DIR/conflicting_bindings.rs:27:24
67+
|
68+
LL | () if let Some(ref mut y @ ref mut z) = x => {}
69+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
70+
| |
71+
| value is mutably borrowed by `y` here
72+
73+
error: cannot borrow value as mutable more than once at a time
74+
--> $DIR/conflicting_bindings.rs:31:51
75+
|
76+
LL | () if let Some(()) = Some(()) && let Some(ref mut y @ ref mut z) = x && true => {}
77+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
78+
| |
79+
| value is mutably borrowed by `y` here
80+
81+
error: aborting due to 10 previous errors
82+

tests/ui/pattern/usefulness/conflicting_bindings.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#![feature(let_chains)]
1+
//@revisions: edition2021 edition2024
2+
//@[edition2021] edition:2021
3+
//@[edition2024] edition:2024
4+
5+
#![cfg_attr(edition2021, feature(let_chains))]
26

37
fn main() {
48
let mut x = Some(String::new());
@@ -23,4 +27,9 @@ fn main() {
2327
() if let Some(ref mut y @ ref mut z) = x => {} //~ ERROR: mutable more than once
2428
_ => {}
2529
}
30+
match () {
31+
() if let Some(()) = Some(()) && let Some(ref mut y @ ref mut z) = x && true => {}
32+
//~^ ERROR: mutable more than once
33+
_ => {}
34+
}
2635
}

tests/ui/rfcs/rfc-2294-if-let-guard/partially-macro-expanded.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//@[edition2021] edition:2021
55
//@[edition2024] edition:2024
66

7-
#![feature(let_chains)]
8-
97
macro_rules! m {
108
(pattern $i:ident) => { Some($i) };
119
(expression $e:expr) => { $e };

tests/ui/rfcs/rfc-2294-if-let-guard/scope.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//@[edition2021] edition:2021
66
//@[edition2024] edition:2024
77

8-
#![feature(let_chains)]
98
#![allow(irrefutable_let_patterns)]
109

1110
fn lhs_let(opt: Option<bool>) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#[rustfmt::skip]
1+
// https://github.com/rust-lang/rust/issues/93150
2+
//@ run-pass
3+
24
fn main() {
35
match true {
46
_ if let true = true && true => {}
5-
//~^ ERROR `let` expressions in this position are unstable
67
_ => {}
78
}
89
}

tests/ui/rfcs/rfc-2497-if-let-chains/issue-93150.stderr

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/rfcs/rfc-2497-if-let-chains/then-else-blocks.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//@ run-pass
2+
//@revisions: edition2021 edition2024
3+
//@[edition2021] edition:2021
4+
//@[edition2024] edition:2024
25

3-
#![feature(let_chains)]
6+
#![cfg_attr(edition2021, feature(let_chains))]
47

58
fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
69
if let Some(first) = opt

0 commit comments

Comments
 (0)