Skip to content

Commit 0917260

Browse files
Add a few basic tests for if-let guards
1 parent 61e69bc commit 0917260

File tree

9 files changed

+190
-35
lines changed

9 files changed

+190
-35
lines changed

src/test/ui/generator/yielding-in-match-guards.rs

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// Thus, `&'_ u8` should be included in type signature
1111
// of the underlying generator.
1212

13+
#![feature(if_let_guard)]
14+
#![allow(incomplete_features)]
15+
1316
async fn f() -> u8 { 1 }
1417
async fn foo() -> [bool; 10] { [false; 10] }
1518

@@ -36,8 +39,16 @@ async fn i(x: u8) {
3639
}
3740
}
3841

42+
async fn j(x: u8) {
43+
match x {
44+
y if let (1, 42) = (f().await, y) => (),
45+
_ => (),
46+
}
47+
}
48+
3949
fn main() {
4050
let _ = g(10);
4151
let _ = h(9);
4252
let _ = i(8);
53+
let _ = j(7);
4354
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(if_let_guard)]
2+
#![allow(incomplete_features)]
3+
4+
fn main() {
5+
match Some(None) {
6+
Some(x) if let Some(y) = x => (x, y),
7+
_ => y, //~ ERROR cannot find value `y`
8+
}
9+
y //~ ERROR cannot find value `y`
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0425]: cannot find value `y` in this scope
2+
--> $DIR/bindings.rs:7:14
3+
|
4+
LL | _ => y,
5+
| ^ not found in this scope
6+
7+
error[E0425]: cannot find value `y` in this scope
8+
--> $DIR/bindings.rs:9:5
9+
|
10+
LL | y
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: no rules expected the token `let`
2-
--> $DIR/feature-gate.rs:81:15
2+
--> $DIR/feature-gate.rs:80:15
33
|
44
LL | macro_rules! use_expr {
55
| --------------------- when calling this macro
@@ -17,7 +17,7 @@ LL | () if let 0 = 1 => {}
1717
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
1818

1919
error[E0658]: `if let` guard is not implemented
20-
--> $DIR/feature-gate.rs:77:12
20+
--> $DIR/feature-gate.rs:76:12
2121
|
2222
LL | () if let 0 = 1 => {}
2323
| ^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | () if let 0 = 1 => {}
2626
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
2727

2828
error[E0658]: `let` expressions in this position are experimental
29-
--> $DIR/feature-gate.rs:11:16
29+
--> $DIR/feature-gate.rs:10:16
3030
|
3131
LL | () if (let 0 = 1) => {}
3232
| ^^^^^^^^^
@@ -35,7 +35,7 @@ LL | () if (let 0 = 1) => {}
3535
= help: add `#![feature(let_chains)]` to the crate attributes to enable
3636

3737
error[E0658]: `let` expressions in this position are experimental
38-
--> $DIR/feature-gate.rs:15:18
38+
--> $DIR/feature-gate.rs:14:18
3939
|
4040
LL | () if (((let 0 = 1))) => {}
4141
| ^^^^^^^^^
@@ -44,7 +44,7 @@ LL | () if (((let 0 = 1))) => {}
4444
= help: add `#![feature(let_chains)]` to the crate attributes to enable
4545

4646
error[E0658]: `let` expressions in this position are experimental
47-
--> $DIR/feature-gate.rs:19:23
47+
--> $DIR/feature-gate.rs:18:23
4848
|
4949
LL | () if true && let 0 = 1 => {}
5050
| ^^^^^^^^^
@@ -53,7 +53,7 @@ LL | () if true && let 0 = 1 => {}
5353
= help: add `#![feature(let_chains)]` to the crate attributes to enable
5454

5555
error[E0658]: `let` expressions in this position are experimental
56-
--> $DIR/feature-gate.rs:23:15
56+
--> $DIR/feature-gate.rs:22:15
5757
|
5858
LL | () if let 0 = 1 && true => {}
5959
| ^^^^^^^^^
@@ -62,7 +62,7 @@ LL | () if let 0 = 1 && true => {}
6262
= help: add `#![feature(let_chains)]` to the crate attributes to enable
6363

6464
error[E0658]: `let` expressions in this position are experimental
65-
--> $DIR/feature-gate.rs:27:16
65+
--> $DIR/feature-gate.rs:26:16
6666
|
6767
LL | () if (let 0 = 1) && true => {}
6868
| ^^^^^^^^^
@@ -71,7 +71,7 @@ LL | () if (let 0 = 1) && true => {}
7171
= help: add `#![feature(let_chains)]` to the crate attributes to enable
7272

7373
error[E0658]: `let` expressions in this position are experimental
74-
--> $DIR/feature-gate.rs:31:24
74+
--> $DIR/feature-gate.rs:30:24
7575
|
7676
LL | () if true && (let 0 = 1) => {}
7777
| ^^^^^^^^^
@@ -80,7 +80,7 @@ LL | () if true && (let 0 = 1) => {}
8080
= help: add `#![feature(let_chains)]` to the crate attributes to enable
8181

8282
error[E0658]: `let` expressions in this position are experimental
83-
--> $DIR/feature-gate.rs:35:16
83+
--> $DIR/feature-gate.rs:34:16
8484
|
8585
LL | () if (let 0 = 1) && (let 0 = 1) => {}
8686
| ^^^^^^^^^
@@ -89,7 +89,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
8989
= help: add `#![feature(let_chains)]` to the crate attributes to enable
9090

9191
error[E0658]: `let` expressions in this position are experimental
92-
--> $DIR/feature-gate.rs:35:31
92+
--> $DIR/feature-gate.rs:34:31
9393
|
9494
LL | () if (let 0 = 1) && (let 0 = 1) => {}
9595
| ^^^^^^^^^
@@ -98,7 +98,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
9898
= help: add `#![feature(let_chains)]` to the crate attributes to enable
9999

100100
error[E0658]: `let` expressions in this position are experimental
101-
--> $DIR/feature-gate.rs:41:15
101+
--> $DIR/feature-gate.rs:40:15
102102
|
103103
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
104104
| ^^^^^^^^^
@@ -107,7 +107,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
107107
= help: add `#![feature(let_chains)]` to the crate attributes to enable
108108

109109
error[E0658]: `let` expressions in this position are experimental
110-
--> $DIR/feature-gate.rs:41:28
110+
--> $DIR/feature-gate.rs:40:28
111111
|
112112
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
113113
| ^^^^^^^^^
@@ -116,7 +116,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
116116
= help: add `#![feature(let_chains)]` to the crate attributes to enable
117117

118118
error[E0658]: `let` expressions in this position are experimental
119-
--> $DIR/feature-gate.rs:41:42
119+
--> $DIR/feature-gate.rs:40:42
120120
|
121121
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
122122
| ^^^^^^^^^
@@ -125,7 +125,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
125125
= help: add `#![feature(let_chains)]` to the crate attributes to enable
126126

127127
error[E0658]: `let` expressions in this position are experimental
128-
--> $DIR/feature-gate.rs:41:55
128+
--> $DIR/feature-gate.rs:40:55
129129
|
130130
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
131131
| ^^^^^^^^^
@@ -134,7 +134,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
134134
= help: add `#![feature(let_chains)]` to the crate attributes to enable
135135

136136
error[E0658]: `let` expressions in this position are experimental
137-
--> $DIR/feature-gate.rs:41:68
137+
--> $DIR/feature-gate.rs:40:68
138138
|
139139
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
140140
| ^^^^^^^^^
@@ -143,7 +143,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
143143
= help: add `#![feature(let_chains)]` to the crate attributes to enable
144144

145145
error[E0658]: `let` expressions in this position are experimental
146-
--> $DIR/feature-gate.rs:53:15
146+
--> $DIR/feature-gate.rs:52:15
147147
|
148148
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
149149
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -152,7 +152,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
152152
= help: add `#![feature(let_chains)]` to the crate attributes to enable
153153

154154
error[E0658]: `let` expressions in this position are experimental
155-
--> $DIR/feature-gate.rs:69:16
155+
--> $DIR/feature-gate.rs:68:16
156156
|
157157
LL | use_expr!((let 0 = 1 && 0 == 0));
158158
| ^^^^^^^^^
@@ -161,7 +161,7 @@ LL | use_expr!((let 0 = 1 && 0 == 0));
161161
= help: add `#![feature(let_chains)]` to the crate attributes to enable
162162

163163
error[E0658]: `let` expressions in this position are experimental
164-
--> $DIR/feature-gate.rs:72:16
164+
--> $DIR/feature-gate.rs:71:16
165165
|
166166
LL | use_expr!((let 0 = 1));
167167
| ^^^^^^^^^
@@ -170,7 +170,7 @@ LL | use_expr!((let 0 = 1));
170170
= help: add `#![feature(let_chains)]` to the crate attributes to enable
171171

172172
error: `let` expressions are not supported here
173-
--> $DIR/feature-gate.rs:11:16
173+
--> $DIR/feature-gate.rs:10:16
174174
|
175175
LL | () if (let 0 = 1) => {}
176176
| ^^^^^^^^^
@@ -179,7 +179,7 @@ LL | () if (let 0 = 1) => {}
179179
= note: as well as when nested within `&&` and parenthesis in those conditions
180180

181181
error: `let` expressions are not supported here
182-
--> $DIR/feature-gate.rs:15:18
182+
--> $DIR/feature-gate.rs:14:18
183183
|
184184
LL | () if (((let 0 = 1))) => {}
185185
| ^^^^^^^^^
@@ -188,7 +188,7 @@ LL | () if (((let 0 = 1))) => {}
188188
= note: as well as when nested within `&&` and parenthesis in those conditions
189189

190190
error: `let` expressions are not supported here
191-
--> $DIR/feature-gate.rs:19:23
191+
--> $DIR/feature-gate.rs:18:23
192192
|
193193
LL | () if true && let 0 = 1 => {}
194194
| ^^^^^^^^^
@@ -197,7 +197,7 @@ LL | () if true && let 0 = 1 => {}
197197
= note: as well as when nested within `&&` and parenthesis in those conditions
198198

199199
error: `let` expressions are not supported here
200-
--> $DIR/feature-gate.rs:23:15
200+
--> $DIR/feature-gate.rs:22:15
201201
|
202202
LL | () if let 0 = 1 && true => {}
203203
| ^^^^^^^^^
@@ -206,7 +206,7 @@ LL | () if let 0 = 1 && true => {}
206206
= note: as well as when nested within `&&` and parenthesis in those conditions
207207

208208
error: `let` expressions are not supported here
209-
--> $DIR/feature-gate.rs:27:16
209+
--> $DIR/feature-gate.rs:26:16
210210
|
211211
LL | () if (let 0 = 1) && true => {}
212212
| ^^^^^^^^^
@@ -215,7 +215,7 @@ LL | () if (let 0 = 1) && true => {}
215215
= note: as well as when nested within `&&` and parenthesis in those conditions
216216

217217
error: `let` expressions are not supported here
218-
--> $DIR/feature-gate.rs:31:24
218+
--> $DIR/feature-gate.rs:30:24
219219
|
220220
LL | () if true && (let 0 = 1) => {}
221221
| ^^^^^^^^^
@@ -224,7 +224,7 @@ LL | () if true && (let 0 = 1) => {}
224224
= note: as well as when nested within `&&` and parenthesis in those conditions
225225

226226
error: `let` expressions are not supported here
227-
--> $DIR/feature-gate.rs:35:16
227+
--> $DIR/feature-gate.rs:34:16
228228
|
229229
LL | () if (let 0 = 1) && (let 0 = 1) => {}
230230
| ^^^^^^^^^
@@ -233,7 +233,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
233233
= note: as well as when nested within `&&` and parenthesis in those conditions
234234

235235
error: `let` expressions are not supported here
236-
--> $DIR/feature-gate.rs:35:31
236+
--> $DIR/feature-gate.rs:34:31
237237
|
238238
LL | () if (let 0 = 1) && (let 0 = 1) => {}
239239
| ^^^^^^^^^
@@ -242,7 +242,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
242242
= note: as well as when nested within `&&` and parenthesis in those conditions
243243

244244
error: `let` expressions are not supported here
245-
--> $DIR/feature-gate.rs:41:15
245+
--> $DIR/feature-gate.rs:40:15
246246
|
247247
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
248248
| ^^^^^^^^^
@@ -251,7 +251,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
251251
= note: as well as when nested within `&&` and parenthesis in those conditions
252252

253253
error: `let` expressions are not supported here
254-
--> $DIR/feature-gate.rs:41:28
254+
--> $DIR/feature-gate.rs:40:28
255255
|
256256
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
257257
| ^^^^^^^^^
@@ -260,7 +260,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
260260
= note: as well as when nested within `&&` and parenthesis in those conditions
261261

262262
error: `let` expressions are not supported here
263-
--> $DIR/feature-gate.rs:41:42
263+
--> $DIR/feature-gate.rs:40:42
264264
|
265265
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
266266
| ^^^^^^^^^
@@ -269,7 +269,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
269269
= note: as well as when nested within `&&` and parenthesis in those conditions
270270

271271
error: `let` expressions are not supported here
272-
--> $DIR/feature-gate.rs:41:55
272+
--> $DIR/feature-gate.rs:40:55
273273
|
274274
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
275275
| ^^^^^^^^^
@@ -278,7 +278,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
278278
= note: as well as when nested within `&&` and parenthesis in those conditions
279279

280280
error: `let` expressions are not supported here
281-
--> $DIR/feature-gate.rs:41:68
281+
--> $DIR/feature-gate.rs:40:68
282282
|
283283
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
284284
| ^^^^^^^^^
@@ -287,7 +287,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
287287
= note: as well as when nested within `&&` and parenthesis in those conditions
288288

289289
error: `let` expressions are not supported here
290-
--> $DIR/feature-gate.rs:53:15
290+
--> $DIR/feature-gate.rs:52:15
291291
|
292292
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
293293
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -296,7 +296,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
296296
= note: as well as when nested within `&&` and parenthesis in those conditions
297297

298298
error: `let` expressions are not supported here
299-
--> $DIR/feature-gate.rs:69:16
299+
--> $DIR/feature-gate.rs:68:16
300300
|
301301
LL | use_expr!((let 0 = 1 && 0 == 0));
302302
| ^^^^^^^^^
@@ -305,14 +305,14 @@ LL | use_expr!((let 0 = 1 && 0 == 0));
305305
= note: as well as when nested within `&&` and parenthesis in those conditions
306306

307307
error: `let` expressions are not supported here
308-
--> $DIR/feature-gate.rs:72:16
308+
--> $DIR/feature-gate.rs:71:16
309309
|
310310
LL | use_expr!((let 0 = 1));
311311
| ^^^^^^^^^
312312
|
313313
= note: only supported directly in conditions of `if`- and `while`-expressions
314314
= note: as well as when nested within `&&` and parenthesis in those conditions
315315

316-
error: aborting due to 36 previous errors
316+
error: aborting due to 35 previous errors
317317

318318
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)