Skip to content

Commit f5567e1

Browse files
committed
organize old well-typed-edition-2024 tests
This doesn't (or at least shouldn't!) add, remove, or change any test cases. I've grouped them by which rule variants they test.
1 parent 4ed44c9 commit f5567e1

File tree

2 files changed

+100
-85
lines changed

2 files changed

+100
-85
lines changed

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

+35-20
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@
1111
#![cfg_attr(structural2024, feature(ref_pat_eat_one_layer_2024_structural))]
1212

1313
pub fn main() {
14-
if let Some(Some(&x)) = &Some(&Some(0)) {
15-
//[stable2021]~^ mismatched types
16-
//[stable2021]~| expected integer, found `&_`
17-
let _: u32 = x;
14+
// Tests not using match ergonomics. These should always succeed with the same bindings.
15+
if let Some(&Some(&mut ref x)) = Some(&Some(&mut 0)) {
16+
let _: &u32 = x;
1817
}
18+
19+
// Tests for differences in how many layers of reference are eaten by reference patterns
1920
if let Some(Some(&x)) = &Some(Some(&0)) {
2021
#[cfg(stable2021)] let _: u32 = x;
2122
#[cfg(any(classic2024, structural2024))] let _: &u32 = x;
2223
}
24+
if let Some(&Some(x)) = &mut Some(&Some(0)) {
25+
// This additionally tests that `&` patterns can eat inherited `&mut` refs.
26+
// This is possible on stable when the real reference being eaten is of a `&` type.
27+
#[cfg(stable2021)] let _: u32 = x;
28+
#[cfg(any(classic2024, structural2024))] let _: &u32 = x;
29+
}
2330
if let Some(Some(&&x)) = &Some(Some(&0)) {
2431
//[stable2021]~^ mismatched types
2532
//[stable2021]~| expected integer, found `&_`
2633
let _: u32 = x;
2734
}
35+
36+
// Tests for eating a lone inherited reference
37+
if let Some(Some(&x)) = &Some(&Some(0)) {
38+
//[stable2021]~^ mismatched types
39+
//[stable2021]~| expected integer, found `&_`
40+
let _: u32 = x;
41+
}
2842
if let Some(&Some(x)) = &Some(Some(0)) {
2943
//[stable2021]~^ mismatched types
3044
//[stable2021]~| expected `Option<{integer}>`, found `&_`
@@ -35,41 +49,42 @@ pub fn main() {
3549
//[stable2021]~| expected integer, found `&mut _`
3650
let _: u32 = x;
3751
}
38-
if let Some(&Some(&x)) = &mut Some(&Some(0)) {
39-
//[stable2021]~^ mismatched types
40-
//[stable2021]~| expected integer, found `&_`
41-
let _: u32 = x;
42-
}
43-
if let Some(&Some(x)) = &mut Some(&Some(0)) {
44-
#[cfg(stable2021)] let _: u32 = x;
45-
#[cfg(any(classic2024, structural2024))] let _: &u32 = x;
46-
}
47-
if let Some(&Some(&mut ref x)) = Some(&Some(&mut 0)) {
48-
let _: &u32 = x;
49-
}
50-
if let Some(&Some(&x)) = &Some(&mut Some(0)) {
52+
53+
// Tests for `&` patterns matching real `&mut` reference types
54+
if let Some(&Some(&x)) = Some(&Some(&mut 0)) {
5155
//[stable2021]~^ mismatched types
5256
//[stable2021]~| types differ in mutability
5357
let _: u32 = x;
5458
}
59+
60+
// Tests for eating only one layer and also eating a lone inherited reference
5561
if let Some(&Some(&x)) = &Some(&Some(0)) {
5662
//[stable2021]~^ mismatched types
5763
//[stable2021]~| expected integer, found `&_`
5864
let _: u32 = x;
5965
}
66+
67+
// Tests for `&` matching a lone inherited possibly-`&mut` reference
6068
if let Some(&Some(Some(&x))) = &Some(Some(&mut Some(0))) {
6169
//[stable2021]~^ mismatched types
6270
//[stable2021]~| expected `Option<&mut Option<{integer}>>`, found `&_`
6371
let _: u32 = x;
6472
}
65-
if let Some(&Some(&x)) = Some(&Some(&mut 0)) {
73+
if let Some(&Some(x)) = &mut Some(Some(0)) {
74+
//[stable2021]~^ mismatched types
75+
//[stable2021]~| expected `Option<{integer}>`, found `&_`
76+
let _: u32 = x;
77+
}
78+
79+
// Tests eating one layer, eating a lone inherited ref, and `&` eating `&mut` (realness varies)
80+
if let Some(&Some(&x)) = &Some(&mut Some(0)) {
6681
//[stable2021]~^ mismatched types
6782
//[stable2021]~| types differ in mutability
6883
let _: u32 = x;
6984
}
70-
if let Some(&Some(x)) = &mut Some(Some(0)) {
85+
if let Some(&Some(&x)) = &mut Some(&Some(0)) {
7186
//[stable2021]~^ mismatched types
72-
//[stable2021]~| expected `Option<{integer}>`, found `&_`
87+
//[stable2021]~| expected integer, found `&_`
7388
let _: u32 = x;
7489
}
7590

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

+65-65
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
error[E0308]: mismatched types
2-
--> $DIR/well-typed-edition-2024.rs:14:22
2+
--> $DIR/well-typed-edition-2024.rs:30:23
33
|
4-
LL | if let Some(Some(&x)) = &Some(&Some(0)) {
5-
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
6-
| |
7-
| expected integer, found `&_`
4+
LL | if let Some(Some(&&x)) = &Some(Some(&0)) {
5+
| ^^ --------------- this expression has type `&Option<Option<&{integer}>>`
6+
| |
7+
| expected integer, found `&_`
88
|
99
= note: expected type `{integer}`
1010
found reference `&_`
1111
help: consider removing `&` from the pattern
1212
|
13-
LL | if let Some(Some(x)) = &Some(&Some(0)) {
14-
| ~
13+
LL - if let Some(Some(&&x)) = &Some(Some(&0)) {
14+
LL + if let Some(Some(&x)) = &Some(Some(&0)) {
15+
|
1516

1617
error[E0308]: mismatched types
17-
--> $DIR/well-typed-edition-2024.rs:23:23
18+
--> $DIR/well-typed-edition-2024.rs:37:22
1819
|
19-
LL | if let Some(Some(&&x)) = &Some(Some(&0)) {
20-
| ^^ --------------- this expression has type `&Option<Option<&{integer}>>`
21-
| |
22-
| expected integer, found `&_`
20+
LL | if let Some(Some(&x)) = &Some(&Some(0)) {
21+
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
22+
| |
23+
| expected integer, found `&_`
2324
|
2425
= note: expected type `{integer}`
2526
found reference `&_`
2627
help: consider removing `&` from the pattern
2728
|
28-
LL - if let Some(Some(&&x)) = &Some(Some(&0)) {
29-
LL + if let Some(Some(&x)) = &Some(Some(&0)) {
30-
|
29+
LL | if let Some(Some(x)) = &Some(&Some(0)) {
30+
| ~
3131

3232
error[E0308]: mismatched types
33-
--> $DIR/well-typed-edition-2024.rs:28:17
33+
--> $DIR/well-typed-edition-2024.rs:42:17
3434
|
3535
LL | if let Some(&Some(x)) = &Some(Some(0)) {
3636
| ^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>`
@@ -41,7 +41,7 @@ LL | if let Some(&Some(x)) = &Some(Some(0)) {
4141
found reference `&_`
4242

4343
error[E0308]: mismatched types
44-
--> $DIR/well-typed-edition-2024.rs:33:22
44+
--> $DIR/well-typed-edition-2024.rs:47:22
4545
|
4646
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
4747
| ^^^^^^ ----------------------- this expression has type `&mut Option<&mut Option<{integer}>>`
@@ -51,7 +51,7 @@ LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
5151
= note: expected type `{integer}`
5252
found mutable reference `&mut _`
5353
note: to declare a mutable binding use: `mut x`
54-
--> $DIR/well-typed-edition-2024.rs:33:22
54+
--> $DIR/well-typed-edition-2024.rs:47:22
5555
|
5656
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
5757
| ^^^^^^
@@ -61,33 +61,22 @@ LL | if let Some(Some(x)) = &mut Some(&mut Some(0)) {
6161
| ~
6262

6363
error[E0308]: mismatched types
64-
--> $DIR/well-typed-edition-2024.rs:38:23
64+
--> $DIR/well-typed-edition-2024.rs:54:23
6565
|
66-
LL | if let Some(&Some(&x)) = &mut Some(&Some(0)) {
67-
| ^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>`
66+
LL | if let Some(&Some(&x)) = Some(&Some(&mut 0)) {
67+
| ^^ ------------------- this expression has type `Option<&Option<&mut {integer}>>`
6868
| |
69-
| expected integer, found `&_`
69+
| types differ in mutability
7070
|
71-
= note: expected type `{integer}`
72-
found reference `&_`
71+
= note: expected mutable reference `&mut {integer}`
72+
found reference `&_`
7373
help: consider removing `&` from the pattern
7474
|
75-
LL | if let Some(&Some(x)) = &mut Some(&Some(0)) {
75+
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
7676
| ~
7777

7878
error[E0308]: mismatched types
79-
--> $DIR/well-typed-edition-2024.rs:50:17
80-
|
81-
LL | if let Some(&Some(&x)) = &Some(&mut Some(0)) {
82-
| ^^^^^^^^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>`
83-
| |
84-
| types differ in mutability
85-
|
86-
= note: expected mutable reference `&mut Option<{integer}>`
87-
found reference `&_`
88-
89-
error[E0308]: mismatched types
90-
--> $DIR/well-typed-edition-2024.rs:55:23
79+
--> $DIR/well-typed-edition-2024.rs:61:23
9180
|
9281
LL | if let Some(&Some(&x)) = &Some(&Some(0)) {
9382
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
@@ -102,7 +91,7 @@ LL | if let Some(&Some(x)) = &Some(&Some(0)) {
10291
| ~
10392

10493
error[E0308]: mismatched types
105-
--> $DIR/well-typed-edition-2024.rs:60:17
94+
--> $DIR/well-typed-edition-2024.rs:68:17
10695
|
10796
LL | if let Some(&Some(Some(&x))) = &Some(Some(&mut Some(0))) {
10897
| ^^^^^^^^^^^^^^^ ------------------------- this expression has type `&Option<Option<&mut Option<{integer}>>>`
@@ -113,22 +102,7 @@ LL | if let Some(&Some(Some(&x))) = &Some(Some(&mut Some(0))) {
113102
found reference `&_`
114103

115104
error[E0308]: mismatched types
116-
--> $DIR/well-typed-edition-2024.rs:65:23
117-
|
118-
LL | if let Some(&Some(&x)) = Some(&Some(&mut 0)) {
119-
| ^^ ------------------- this expression has type `Option<&Option<&mut {integer}>>`
120-
| |
121-
| types differ in mutability
122-
|
123-
= note: expected mutable reference `&mut {integer}`
124-
found reference `&_`
125-
help: consider removing `&` from the pattern
126-
|
127-
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
128-
| ~
129-
130-
error[E0308]: mismatched types
131-
--> $DIR/well-typed-edition-2024.rs:70:17
105+
--> $DIR/well-typed-edition-2024.rs:73:17
132106
|
133107
LL | if let Some(&Some(x)) = &mut Some(Some(0)) {
134108
| ^^^^^^^^ ------------------ this expression has type `&mut Option<Option<{integer}>>`
@@ -139,7 +113,33 @@ LL | if let Some(&Some(x)) = &mut Some(Some(0)) {
139113
found reference `&_`
140114

141115
error[E0308]: mismatched types
142-
--> $DIR/well-typed-edition-2024.rs:78:10
116+
--> $DIR/well-typed-edition-2024.rs:80:17
117+
|
118+
LL | if let Some(&Some(&x)) = &Some(&mut Some(0)) {
119+
| ^^^^^^^^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>`
120+
| |
121+
| types differ in mutability
122+
|
123+
= note: expected mutable reference `&mut Option<{integer}>`
124+
found reference `&_`
125+
126+
error[E0308]: mismatched types
127+
--> $DIR/well-typed-edition-2024.rs:85:23
128+
|
129+
LL | if let Some(&Some(&x)) = &mut Some(&Some(0)) {
130+
| ^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>`
131+
| |
132+
| expected integer, found `&_`
133+
|
134+
= note: expected type `{integer}`
135+
found reference `&_`
136+
help: consider removing `&` from the pattern
137+
|
138+
LL | if let Some(&Some(x)) = &mut Some(&Some(0)) {
139+
| ~
140+
141+
error[E0308]: mismatched types
142+
--> $DIR/well-typed-edition-2024.rs:93:10
143143
|
144144
LL | let [&mut x] = &mut [&0];
145145
| ^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -149,7 +149,7 @@ LL | let [&mut x] = &mut [&0];
149149
= note: expected reference `&{integer}`
150150
found mutable reference `&mut _`
151151
note: to declare a mutable binding use: `mut x`
152-
--> $DIR/well-typed-edition-2024.rs:78:10
152+
--> $DIR/well-typed-edition-2024.rs:93:10
153153
|
154154
LL | let [&mut x] = &mut [&0];
155155
| ^^^^^^
@@ -160,7 +160,7 @@ LL + let [x] = &mut [&0];
160160
|
161161

162162
error[E0308]: mismatched types
163-
--> $DIR/well-typed-edition-2024.rs:83:10
163+
--> $DIR/well-typed-edition-2024.rs:98:10
164164
|
165165
LL | let [&mut ref x] = &mut [&0];
166166
| ^^^^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -170,7 +170,7 @@ LL | let [&mut ref x] = &mut [&0];
170170
= note: expected reference `&{integer}`
171171
found mutable reference `&mut _`
172172
note: to declare a mutable binding use: `mut x`
173-
--> $DIR/well-typed-edition-2024.rs:83:10
173+
--> $DIR/well-typed-edition-2024.rs:98:10
174174
|
175175
LL | let [&mut ref x] = &mut [&0];
176176
| ^^^^^^^^^^
@@ -181,7 +181,7 @@ LL + let [ref x] = &mut [&0];
181181
|
182182

183183
error[E0308]: mismatched types
184-
--> $DIR/well-typed-edition-2024.rs:88:10
184+
--> $DIR/well-typed-edition-2024.rs:103:10
185185
|
186186
LL | let [&mut ref mut x] = &mut [&0];
187187
| ^^^^^^^^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -191,7 +191,7 @@ LL | let [&mut ref mut x] = &mut [&0];
191191
= note: expected reference `&{integer}`
192192
found mutable reference `&mut _`
193193
note: to declare a mutable binding use: `mut x`
194-
--> $DIR/well-typed-edition-2024.rs:88:10
194+
--> $DIR/well-typed-edition-2024.rs:103:10
195195
|
196196
LL | let [&mut ref mut x] = &mut [&0];
197197
| ^^^^^^^^^^^^^^
@@ -202,7 +202,7 @@ LL + let [ref mut x] = &mut [&0];
202202
|
203203

204204
error[E0308]: mismatched types
205-
--> $DIR/well-typed-edition-2024.rs:93:10
205+
--> $DIR/well-typed-edition-2024.rs:108:10
206206
|
207207
LL | let [&mut mut x] = &mut [&0];
208208
| ^^^^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -212,7 +212,7 @@ LL | let [&mut mut x] = &mut [&0];
212212
= note: expected reference `&{integer}`
213213
found mutable reference `&mut _`
214214
note: to declare a mutable binding use: `mut x`
215-
--> $DIR/well-typed-edition-2024.rs:93:10
215+
--> $DIR/well-typed-edition-2024.rs:108:10
216216
|
217217
LL | let [&mut mut x] = &mut [&0];
218218
| ^^^^^^^^^^
@@ -223,7 +223,7 @@ LL + let [mut x] = &mut [&0];
223223
|
224224

225225
error[E0308]: mismatched types
226-
--> $DIR/well-typed-edition-2024.rs:98:10
226+
--> $DIR/well-typed-edition-2024.rs:113:10
227227
|
228228
LL | let [&mut &x] = &mut [&0];
229229
| ^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -234,7 +234,7 @@ LL | let [&mut &x] = &mut [&0];
234234
found mutable reference `&mut _`
235235

236236
error[E0308]: mismatched types
237-
--> $DIR/well-typed-edition-2024.rs:103:10
237+
--> $DIR/well-typed-edition-2024.rs:118:10
238238
|
239239
LL | let [&mut &ref x] = &mut [&0];
240240
| ^^^^^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`
@@ -245,7 +245,7 @@ LL | let [&mut &ref x] = &mut [&0];
245245
found mutable reference `&mut _`
246246

247247
error[E0308]: mismatched types
248-
--> $DIR/well-typed-edition-2024.rs:108:10
248+
--> $DIR/well-typed-edition-2024.rs:123:10
249249
|
250250
LL | let [&mut &(mut x)] = &mut [&0];
251251
| ^^^^^^^^^^^^^ --------- this expression has type `&mut [&{integer}; 1]`

0 commit comments

Comments
 (0)