Skip to content

Commit 493156c

Browse files
committed
remove Rule 3 from ref_pat_eat_one_layer_2024
This required some changes to tests: - `ref_pat_eat_one_layer_2021.rs` had a test for Rule 3; I'll be handling tests for earlier editions in a later commit, so as a stopgap I've #[cfg]ed it out. - One test case had to be moved from `well-typed-edition-2024.rs` to `borrowck-errors.rs` in order to get borrowck to run on it and emit an error.
1 parent 562c522 commit 493156c

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
237237
fn downgrade_mut_inside_shared(&self) -> bool {
238238
// NB: RFC 3627 proposes stabilizing Rule 3 in all editions. If we adopt the same behavior
239239
// across all editions, this may be removed.
240-
self.tcx.features().ref_pat_eat_one_layer_2024()
241-
|| self.tcx.features().ref_pat_eat_one_layer_2024_structural()
240+
self.tcx.features().ref_pat_eat_one_layer_2024_structural()
242241
}
243242

244243
/// Experimental pattern feature: when do reference patterns match against inherited references?

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
1919
LL | let &ref mut x = &0;
2020
| ^^^^^^^^^ cannot borrow as mutable
2121

22-
error: aborting due to 2 previous errors
22+
error[E0596]: cannot borrow data in a `&` reference as mutable
23+
--> $DIR/borrowck-errors.rs:17:23
24+
|
25+
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
26+
| ^ cannot borrow as mutable
27+
28+
error: aborting due to 3 previous errors
2329

2430
Some errors have detailed explanations: E0507, E0596.
2531
For more information about an error, try `rustc --explain E0507`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ pub fn main() {
1313

1414
let &ref mut x = &0;
1515
//~^ cannot borrow data in a `&` reference as mutable [E0596]
16+
17+
if let &Some(Some(x)) = &Some(&mut Some(0)) {
18+
//[classic]~^ ERROR: cannot borrow data in a `&` reference as mutable
19+
let _: &u32 = x;
20+
}
1621
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.classic.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ help: replace this `&mut` pattern with `&`
4646
LL | if let Some(&Some(&_)) = &Some(&Some(0)) {
4747
| ~
4848

49-
error[E0308]: mismatched types
50-
--> $DIR/pattern-errors.rs:31:23
51-
|
52-
LL | if let Some(&Some(&mut _)) = &Some(&mut Some(0)) {
53-
| ^^^^^
54-
|
55-
= note: cannot match inherited `&` with `&mut` pattern
56-
help: replace this `&mut` pattern with `&`
57-
|
58-
LL | if let Some(&Some(&_)) = &Some(&mut Some(0)) {
59-
| ~
60-
6149
error[E0308]: mismatched types
6250
--> $DIR/pattern-errors.rs:34:23
6351
|
@@ -70,18 +58,6 @@ help: replace this `&mut` pattern with `&`
7058
LL | if let Some(&Some(&_)) = &mut Some(&Some(0)) {
7159
| ~
7260

73-
error[E0308]: mismatched types
74-
--> $DIR/pattern-errors.rs:37:29
75-
|
76-
LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) {
77-
| ^^^^^
78-
|
79-
= note: cannot match inherited `&` with `&mut` pattern
80-
help: replace this `&mut` pattern with `&`
81-
|
82-
LL | if let Some(&Some(Some((&_)))) = &Some(Some(&mut Some(0))) {
83-
| ~
84-
8561
error[E0308]: mismatched types
8662
--> $DIR/pattern-errors.rs:40:17
8763
|
@@ -106,6 +82,6 @@ help: replace this `&mut` pattern with `&`
10682
LL | if let Some(&Some(x)) = &Some(Some(0)) {
10783
| ~
10884

109-
error: aborting due to 9 previous errors
85+
error: aborting due to 7 previous errors
11086

11187
For more information about this error, try `rustc --explain E0308`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ pub fn main() {
2929
//~^ ERROR: mismatched types
3030
}
3131
if let Some(&Some(&mut _)) = &Some(&mut Some(0)) {
32-
//~^ ERROR: mismatched types
32+
//[structural]~^ ERROR: mismatched types
3333
}
3434
if let Some(&Some(&mut _)) = &mut Some(&Some(0)) {
3535
//~^ ERROR: mismatched types
3636
}
3737
if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) {
38-
//~^ ERROR: mismatched types
38+
//[structural]~^ ERROR: mismatched types
3939
}
4040
if let Some(&mut Some(x)) = &Some(Some(0)) {
4141
//~^ ERROR: mismatched types

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref_pat_eat_one_layer_2021.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
77

88
pub fn main() {
9+
#[cfg(structural)]
910
if let &Some(Some(x)) = &Some(&mut Some(0)) {
1011
let _: &u32 = x;
1112
}
13+
1214
if let Some(&x) = Some(&mut 0) {
1315
let _: u32 = x;
1416
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ pub fn main() {
3535
if let Some(&Some(&mut ref x)) = Some(&Some(&mut 0)) {
3636
let _: &u32 = x;
3737
}
38-
if let &Some(Some(x)) = &Some(&mut Some(0)) {
39-
let _: &u32 = x;
40-
}
4138
if let Some(&Some(&x)) = &Some(&mut Some(0)) {
4239
let _: u32 = x;
4340
}

0 commit comments

Comments
 (0)