Skip to content

Commit 7d3c748

Browse files
authored
Unrolled build for rust-lang#127369
Rollup merge of rust-lang#127369 - Jules-Bertholet:match-ergonomics-2021, r=Nadrieril Match ergonomics 2024: align with RFC again - `&` matches `&mut` on old editions - Add some more tests r? ``@Nadrieril`` cc rust-lang#123076 ``@rustbot`` label A-edition-2024 A-patterns
2 parents 51917e2 + 76da7ae commit 7d3c748

9 files changed

+142
-49
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22172217
debug!("check_pat_ref: expected={:?}", expected);
22182218
match *expected.kind() {
22192219
ty::Ref(_, r_ty, r_mutbl)
2220-
if (new_match_ergonomics && r_mutbl >= pat_mutbl)
2220+
if (no_ref_mut_behind_and && r_mutbl >= pat_mutbl)
22212221
|| r_mutbl == pat_mutbl =>
22222222
{
22232223
if no_ref_mut_behind_and && r_mutbl == Mutability::Not {
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
1+
//@ run-pass
12
//@ edition: 2021
3+
//@ revisions: classic structural both
24
#![allow(incomplete_features)]
3-
#![feature(ref_pat_eat_one_layer_2024)]
5+
#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))]
6+
#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))]
7+
48
pub fn main() {
5-
if let Some(Some(&x)) = &Some(&Some(0)) {
6-
//~^ ERROR: mismatched types
7-
let _: u32 = x;
8-
}
9-
if let Some(Some(&x)) = &Some(Some(&0)) {
9+
if let &Some(Some(x)) = &Some(&mut Some(0)) {
1010
let _: &u32 = x;
11-
//~^ ERROR: mismatched types
12-
}
13-
if let Some(Some(&&x)) = &Some(Some(&0)) {
14-
//~^ ERROR: mismatched types
15-
let _: u32 = x;
16-
}
17-
if let Some(&Some(x)) = &Some(Some(0)) {
18-
//~^ ERROR: mismatched types
19-
let _: u32 = x;
20-
}
21-
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
22-
//~^ ERROR: mismatched types
23-
let _: u32 = x;
24-
}
25-
if let Some(Some(&x)) = &Some(&Some(0)) {
26-
//~^ ERROR: mismatched types
27-
let _: u32 = x;
28-
}
29-
if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
30-
//~^ ERROR: mismatched types
31-
let _: u32 = x;
3211
}
33-
if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
34-
//~^ ERROR: mismatched types
12+
if let Some(&x) = Some(&mut 0) {
3513
let _: u32 = x;
3614
}
3715
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ edition: 2021
2+
#![allow(incomplete_features)]
3+
#![feature(ref_pat_eat_one_layer_2024)]
4+
pub fn main() {
5+
if let Some(Some(&x)) = &Some(&Some(0)) {
6+
//~^ ERROR: mismatched types
7+
let _: u32 = x;
8+
}
9+
if let Some(Some(&x)) = &Some(Some(&0)) {
10+
let _: &u32 = x;
11+
//~^ ERROR: mismatched types
12+
}
13+
if let Some(Some(&&x)) = &Some(Some(&0)) {
14+
//~^ ERROR: mismatched types
15+
let _: u32 = x;
16+
}
17+
if let Some(&Some(x)) = &Some(Some(0)) {
18+
//~^ ERROR: mismatched types
19+
let _: u32 = x;
20+
}
21+
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
22+
//~^ ERROR: mismatched types
23+
let _: u32 = x;
24+
}
25+
if let Some(Some(&x)) = &Some(&Some(0)) {
26+
//~^ ERROR: mismatched types
27+
let _: u32 = x;
28+
}
29+
if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
30+
//~^ ERROR: mismatched types
31+
let _: u32 = x;
32+
}
33+
if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
34+
//~^ ERROR: mismatched types
35+
let _: u32 = x;
36+
}
37+
}

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/ref_pat_eat_one_layer_2021.rs:5:22
2+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:5:22
33
|
44
LL | if let Some(Some(&x)) = &Some(&Some(0)) {
55
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
@@ -14,7 +14,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) {
1414
| ~
1515

1616
error[E0308]: mismatched types
17-
--> $DIR/ref_pat_eat_one_layer_2021.rs:10:23
17+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:10:23
1818
|
1919
LL | let _: &u32 = x;
2020
| ---- ^ expected `&u32`, found integer
@@ -27,7 +27,7 @@ LL | let _: &u32 = &x;
2727
| +
2828

2929
error[E0308]: mismatched types
30-
--> $DIR/ref_pat_eat_one_layer_2021.rs:13:23
30+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:13:23
3131
|
3232
LL | if let Some(Some(&&x)) = &Some(Some(&0)) {
3333
| ^^ --------------- this expression has type `&Option<Option<&{integer}>>`
@@ -43,7 +43,7 @@ LL + if let Some(Some(&x)) = &Some(Some(&0)) {
4343
|
4444

4545
error[E0308]: mismatched types
46-
--> $DIR/ref_pat_eat_one_layer_2021.rs:17:17
46+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:17:17
4747
|
4848
LL | if let Some(&Some(x)) = &Some(Some(0)) {
4949
| ^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>`
@@ -54,7 +54,7 @@ LL | if let Some(&Some(x)) = &Some(Some(0)) {
5454
found reference `&_`
5555

5656
error[E0308]: mismatched types
57-
--> $DIR/ref_pat_eat_one_layer_2021.rs:21:22
57+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:21:22
5858
|
5959
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
6060
| ^^^^^^ ----------------------- this expression has type `&mut Option<&mut Option<{integer}>>`
@@ -64,7 +64,7 @@ LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
6464
= note: expected type `{integer}`
6565
found mutable reference `&mut _`
6666
note: to declare a mutable binding use: `mut x`
67-
--> $DIR/ref_pat_eat_one_layer_2021.rs:21:22
67+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:21:22
6868
|
6969
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
7070
| ^^^^^^
@@ -74,7 +74,7 @@ LL | if let Some(Some(x)) = &mut Some(&mut Some(0)) {
7474
| ~
7575

7676
error[E0308]: mismatched types
77-
--> $DIR/ref_pat_eat_one_layer_2021.rs:25:22
77+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:25:22
7878
|
7979
LL | if let Some(Some(&x)) = &Some(&Some(0)) {
8080
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
@@ -89,7 +89,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) {
8989
| ~
9090

9191
error[E0308]: mismatched types
92-
--> $DIR/ref_pat_eat_one_layer_2021.rs:29:27
92+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:29:27
9393
|
9494
LL | if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
9595
| ^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>`
@@ -104,7 +104,7 @@ LL | if let Some(&mut Some(x)) = &Some(&mut Some(0)) {
104104
| ~
105105

106106
error[E0308]: mismatched types
107-
--> $DIR/ref_pat_eat_one_layer_2021.rs:33:23
107+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:33:23
108108
|
109109
LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
110110
| ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>`
@@ -114,7 +114,7 @@ LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
114114
= note: expected type `{integer}`
115115
found mutable reference `&mut _`
116116
note: to declare a mutable binding use: `mut x`
117-
--> $DIR/ref_pat_eat_one_layer_2021.rs:33:23
117+
--> $DIR/ref_pat_eat_one_layer_2021_fail.rs:33:23
118118
|
119119
LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
120120
| ^^^^^^

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs

+23
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,27 @@ pub fn main() {
6363
if let Some(&mut x) = &Some(&mut 0) {
6464
let _: &u32 = x;
6565
}
66+
67+
fn generic<R: Ref>() -> (R, bool) {
68+
R::meow()
69+
}
70+
71+
trait Ref: Sized {
72+
fn meow() -> (Self, bool);
73+
}
74+
75+
impl Ref for &'static [(); 0] {
76+
fn meow() -> (Self, bool) {
77+
(&[], false)
78+
}
79+
}
80+
81+
impl Ref for &'static mut [(); 0] {
82+
fn meow() -> (Self, bool) {
83+
(&mut [], true)
84+
}
85+
}
86+
87+
let (&_, b) = generic();
88+
assert!(!b);
6689
}

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.both.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ LL | let Foo(mut a) = &mut Foo(0);
150150
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
151151
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
152152

153-
error: aborting due to 14 previous errors
153+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
154+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
155+
|
156+
LL | let &_ = generic();
157+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
158+
|
159+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
160+
note: required by a bound in `generic`
161+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
162+
|
163+
LL | fn generic<R: Ref>() -> R {
164+
| ^^^ required by this bound in `generic`
165+
166+
error: aborting due to 15 previous errors
154167

155-
Some errors have detailed explanations: E0308, E0658.
156-
For more information about an error, try `rustc --explain E0308`.
168+
Some errors have detailed explanations: E0277, E0308, E0658.
169+
For more information about an error, try `rustc --explain E0277`.

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.classic.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,20 @@ LL | let Foo(mut a) = &mut Foo(0);
180180
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
181181
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
182182

183-
error: aborting due to 16 previous errors
183+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
184+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
185+
|
186+
LL | let &_ = generic();
187+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
188+
|
189+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
190+
note: required by a bound in `generic`
191+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
192+
|
193+
LL | fn generic<R: Ref>() -> R {
194+
| ^^^ required by this bound in `generic`
195+
196+
error: aborting due to 17 previous errors
184197

185-
Some errors have detailed explanations: E0308, E0658.
186-
For more information about an error, try `rustc --explain E0308`.
198+
Some errors have detailed explanations: E0277, E0308, E0658.
199+
For more information about an error, try `rustc --explain E0277`.

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs

+16
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@ pub fn main() {
6565
let Foo(mut a) = &mut Foo(0);
6666
//~^ ERROR: binding cannot be both mutable and by-reference
6767
a = &mut 42;
68+
69+
fn generic<R: Ref>() -> R {
70+
R::meow()
71+
}
72+
73+
trait Ref: Sized {
74+
fn meow() -> Self;
75+
}
76+
77+
impl Ref for &'static mut [(); 0] {
78+
fn meow() -> Self {
79+
&mut []
80+
}
81+
}
82+
83+
let &_ = generic(); //~ERROR: the trait bound `&_: main::Ref` is not satisfied [E0277]
6884
}

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.structural.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,20 @@ LL | let Foo(mut a) = &mut Foo(0);
161161
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
162162
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
163163

164-
error: aborting due to 15 previous errors
164+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
165+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
166+
|
167+
LL | let &_ = generic();
168+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
169+
|
170+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
171+
note: required by a bound in `generic`
172+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
173+
|
174+
LL | fn generic<R: Ref>() -> R {
175+
| ^^^ required by this bound in `generic`
176+
177+
error: aborting due to 16 previous errors
165178

166-
Some errors have detailed explanations: E0308, E0658.
167-
For more information about an error, try `rustc --explain E0308`.
179+
Some errors have detailed explanations: E0277, E0308, E0658.
180+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)