1
+ //@ revisions: no_feature feature nothing
2
+ //@ edition: 2021
1
3
// Here we test that `lowering` behaves correctly wrt. `let $pats = $expr` expressions.
2
4
//
3
5
// We want to make sure that `let` is banned in situations other than:
17
19
//
18
20
// To that end, we check some positions which is not part of the language above.
19
21
20
- #![ feature( let_chains) ] // Avoid inflating `.stderr` with overzealous gates in this test.
22
+ // Avoid inflating `.stderr` with overzealous gates (or test what happens if you disable the gate)
23
+ #![ cfg_attr( not( no_feature) , feature( let_chains) ) ]
21
24
22
25
#![ allow( irrefutable_let_patterns) ]
23
26
24
27
use std:: ops:: Range ;
25
28
26
29
fn main ( ) { }
27
30
31
+ #[ cfg( not( nothing) ) ]
28
32
fn _if ( ) {
29
33
if ( let 0 = 1 ) { }
30
34
//~^ ERROR expected expression, found `let` statement
@@ -46,8 +50,11 @@ fn _if() {
46
50
//~^ ERROR expected expression, found `let` statement
47
51
//~| ERROR expected expression, found `let` statement
48
52
//~| ERROR expected expression, found `let` statement
53
+ //[no_feature]~| ERROR `let` expressions in this position are unstable
54
+ //[no_feature]~| ERROR `let` expressions in this position are unstable
49
55
}
50
56
57
+ #[ cfg( not( nothing) ) ]
51
58
fn _while ( ) {
52
59
while ( let 0 = 1 ) { }
53
60
//~^ ERROR expected expression, found `let` statement
@@ -69,8 +76,11 @@ fn _while() {
69
76
//~^ ERROR expected expression, found `let` statement
70
77
//~| ERROR expected expression, found `let` statement
71
78
//~| ERROR expected expression, found `let` statement
79
+ //[no_feature]~| ERROR `let` expressions in this position are unstable
80
+ //[no_feature]~| ERROR `let` expressions in this position are unstable
72
81
}
73
82
83
+ #[ cfg( not( nothing) ) ]
74
84
fn _macros ( ) {
75
85
macro_rules! use_expr {
76
86
( $e: expr) => {
@@ -79,11 +89,12 @@ fn _macros() {
79
89
}
80
90
}
81
91
use_expr ! ( ( let 0 = 1 && 0 == 0 ) ) ;
82
- //~^ ERROR expected expression, found `let` statement
92
+ //[feature,no_feature] ~^ ERROR expected expression, found `let` statement
83
93
use_expr ! ( ( let 0 = 1 ) ) ;
84
- //~^ ERROR expected expression, found `let` statement
94
+ //[feature,no_feature] ~^ ERROR expected expression, found `let` statement
85
95
}
86
96
97
+ #[ cfg( not( nothing) ) ]
87
98
fn nested_within_if_expr ( ) {
88
99
if & let 0 = 0 { }
89
100
//~^ ERROR expected expression, found `let` statement
@@ -97,7 +108,7 @@ fn nested_within_if_expr() {
97
108
98
109
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
99
110
if let 0 = 0 ? { }
100
- //~^ ERROR the `?` operator can only be applied to values that implement `Try`
111
+ //[feature,no_feature] ~^ ERROR the `?` operator can only be applied to values that implement `Try`
101
112
Ok ( ( ) )
102
113
}
103
114
if ( let 0 = 0 ) ? { }
@@ -118,7 +129,7 @@ fn nested_within_if_expr() {
118
129
119
130
if true ..( let 0 = 0 ) { }
120
131
//~^ ERROR expected expression, found `let` statement
121
- //~| ERROR mismatched types
132
+ //[feature,no_feature] ~| ERROR mismatched types
122
133
if ..( let 0 = 0 ) { }
123
134
//~^ ERROR expected expression, found `let` statement
124
135
if ( let 0 = 0 ) .. { }
@@ -127,27 +138,54 @@ fn nested_within_if_expr() {
127
138
// Binds as `(let ... = true)..true &&/|| false`.
128
139
if let Range { start : _, end : _ } = true ..true && false { }
129
140
//~^ ERROR expected expression, found `let` statement
130
- //~| ERROR mismatched types
141
+ //[feature,no_feature] ~| ERROR mismatched types
131
142
if let Range { start : _, end : _ } = true ..true || false { }
132
143
//~^ ERROR expected expression, found `let` statement
133
- //~| ERROR mismatched types
144
+ //[feature,no_feature] ~| ERROR mismatched types
134
145
135
146
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
136
147
const F : fn ( ) -> bool = || true ;
137
148
if let Range { start : F , end } = F ..|| true { }
138
149
//~^ ERROR expected expression, found `let` statement
139
- //~| ERROR mismatched types
150
+ //[feature,no_feature] ~| ERROR mismatched types
140
151
141
152
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
142
153
let t = & & true ;
143
154
if let Range { start : true , end } = t..&&false { }
144
155
//~^ ERROR expected expression, found `let` statement
145
- //~| ERROR mismatched types
156
+ //[feature,no_feature] ~| ERROR mismatched types
146
157
147
158
if let true = let true = true { }
148
159
//~^ ERROR expected expression, found `let` statement
160
+
161
+ if return let 0 = 0 { }
162
+ //~^ ERROR expected expression, found `let` statement
163
+
164
+ loop { if break let 0 = 0 { } }
165
+ //~^ ERROR expected expression, found `let` statement
166
+
167
+ if ( match let 0 = 0 { _ => { false } } ) { }
168
+ //~^ ERROR expected expression, found `let` statement
169
+
170
+ if ( let 0 = 0 , false ) . 1 { }
171
+ //~^ ERROR expected expression, found `let` statement
172
+
173
+ if ( let 0 = 0 , ) { }
174
+ //~^ ERROR expected expression, found `let` statement
175
+
176
+ async fn foo ( ) {
177
+ if ( let 0 = 0 ) . await { }
178
+ //~^ ERROR expected expression, found `let` statement
179
+ }
180
+
181
+ if ( || let 0 = 0 ) { }
182
+ //~^ ERROR expected expression, found `let` statement
183
+
184
+ if ( let 0 = 0 ) ( ) { }
185
+ //~^ ERROR expected expression, found `let` statement
149
186
}
150
187
188
+ #[ cfg( not( nothing) ) ]
151
189
fn nested_within_while_expr ( ) {
152
190
while & let 0 = 0 { }
153
191
//~^ ERROR expected expression, found `let` statement
@@ -161,7 +199,7 @@ fn nested_within_while_expr() {
161
199
162
200
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
163
201
while let 0 = 0 ? { }
164
- //~^ ERROR the `?` operator can only be applied to values that implement `Try`
202
+ //[feature,no_feature] ~^ ERROR the `?` operator can only be applied to values that implement `Try`
165
203
Ok ( ( ) )
166
204
}
167
205
while ( let 0 = 0 ) ? { }
@@ -182,7 +220,7 @@ fn nested_within_while_expr() {
182
220
183
221
while true ..( let 0 = 0 ) { }
184
222
//~^ ERROR expected expression, found `let` statement
185
- //~| ERROR mismatched types
223
+ //[feature,no_feature] ~| ERROR mismatched types
186
224
while ..( let 0 = 0 ) { }
187
225
//~^ ERROR expected expression, found `let` statement
188
226
while ( let 0 = 0 ) .. { }
@@ -191,27 +229,54 @@ fn nested_within_while_expr() {
191
229
// Binds as `(let ... = true)..true &&/|| false`.
192
230
while let Range { start : _, end : _ } = true ..true && false { }
193
231
//~^ ERROR expected expression, found `let` statement
194
- //~| ERROR mismatched types
232
+ //[feature,no_feature] ~| ERROR mismatched types
195
233
while let Range { start : _, end : _ } = true ..true || false { }
196
234
//~^ ERROR expected expression, found `let` statement
197
- //~| ERROR mismatched types
235
+ //[feature,no_feature] ~| ERROR mismatched types
198
236
199
237
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
200
238
const F : fn ( ) -> bool = || true ;
201
239
while let Range { start : F , end } = F ..|| true { }
202
240
//~^ ERROR expected expression, found `let` statement
203
- //~| ERROR mismatched types
241
+ //[feature,no_feature] ~| ERROR mismatched types
204
242
205
243
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
206
244
let t = & & true ;
207
245
while let Range { start : true , end } = t..&&false { }
208
246
//~^ ERROR expected expression, found `let` statement
209
- //~| ERROR mismatched types
247
+ //[feature,no_feature] ~| ERROR mismatched types
210
248
211
249
while let true = let true = true { }
212
250
//~^ ERROR expected expression, found `let` statement
251
+
252
+ while return let 0 = 0 { }
253
+ //~^ ERROR expected expression, found `let` statement
254
+
255
+ ' outer: loop { while break ' outer let 0 = 0 { } }
256
+ //~^ ERROR expected expression, found `let` statement
257
+
258
+ while ( match let 0 = 0 { _ => { false } } ) { }
259
+ //~^ ERROR expected expression, found `let` statement
260
+
261
+ while ( let 0 = 0 , false ) . 1 { }
262
+ //~^ ERROR expected expression, found `let` statement
263
+
264
+ while ( let 0 = 0 , ) { }
265
+ //~^ ERROR expected expression, found `let` statement
266
+
267
+ async fn foo ( ) {
268
+ while ( let 0 = 0 ) . await { }
269
+ //~^ ERROR expected expression, found `let` statement
270
+ }
271
+
272
+ while ( || let 0 = 0 ) { }
273
+ //~^ ERROR expected expression, found `let` statement
274
+
275
+ while ( let 0 = 0 ) ( ) { }
276
+ //~^ ERROR expected expression, found `let` statement
213
277
}
214
278
279
+ #[ cfg( not( nothing) ) ]
215
280
fn not_error_because_clarified_intent ( ) {
216
281
if let Range { start : _, end : _ } = ( true ..true || false ) { }
217
282
@@ -222,6 +287,7 @@ fn not_error_because_clarified_intent() {
222
287
while let Range { start : _, end : _ } = ( true ..true && false ) { }
223
288
}
224
289
290
+ #[ cfg( not( nothing) ) ]
225
291
fn outside_if_and_while_expr ( ) {
226
292
& let 0 = 0 ;
227
293
//~^ ERROR expected expression, found `let` statement
@@ -232,10 +298,12 @@ fn outside_if_and_while_expr() {
232
298
//~^ ERROR expected expression, found `let` statement
233
299
-let 0 = 0 ;
234
300
//~^ ERROR expected expression, found `let` statement
301
+ let _ = let _ = 3 ;
302
+ //~^ ERROR expected expression, found `let` statement
235
303
236
304
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
237
305
let 0 = 0 ?;
238
- //~^ ERROR the `?` operator can only be applied to values that implement `Try`
306
+ //[feature,no_feature] ~^ ERROR the `?` operator can only be applied to values that implement `Try`
239
307
Ok ( ( ) )
240
308
}
241
309
( let 0 = 0 ) ?;
@@ -260,8 +328,8 @@ fn outside_if_and_while_expr() {
260
328
//~^ ERROR expected expression, found `let` statement
261
329
262
330
( let Range { start : _, end : _ } = true ..true || false ) ;
263
- //~^ ERROR mismatched types
264
- //~| ERROR expected expression, found `let` statement
331
+ //~^ ERROR expected expression, found `let` statement
332
+ //[feature,no_feature] ~| ERROR mismatched types
265
333
266
334
( let true = let true = true ) ;
267
335
//~^ ERROR expected expression, found `let` statement
@@ -285,6 +353,7 @@ fn outside_if_and_while_expr() {
285
353
}
286
354
287
355
// Let's make sure that `let` inside const generic arguments are considered.
356
+ #[ cfg( not( nothing) ) ]
288
357
fn inside_const_generic_arguments ( ) {
289
358
struct A < const B : bool > ;
290
359
impl < const B : bool > A < { B } > { const O : u32 = 5 ; }
@@ -317,6 +386,7 @@ fn inside_const_generic_arguments() {
317
386
>:: O == 5 { }
318
387
}
319
388
389
+ #[ cfg( not( nothing) ) ]
320
390
fn with_parenthesis ( ) {
321
391
let opt = Some ( Some ( 1i32 ) ) ;
322
392
@@ -332,6 +402,7 @@ fn with_parenthesis() {
332
402
//~| ERROR expected expression, found `let` statement
333
403
}
334
404
if let Some ( a) = opt && ( true && true ) {
405
+ //[no_feature]~^ ERROR `let` expressions in this position are unstable
335
406
}
336
407
337
408
if ( let Some ( a) = opt && ( let Some ( b) = a) ) && b == 1 {
@@ -347,14 +418,18 @@ fn with_parenthesis() {
347
418
}
348
419
349
420
if ( true && ( true ) ) && let Some ( a) = opt {
421
+ //[no_feature]~^ ERROR `let` expressions in this position are unstable
350
422
}
351
423
if ( true ) && let Some ( a) = opt {
424
+ //[no_feature]~^ ERROR `let` expressions in this position are unstable
352
425
}
353
426
if true && let Some ( a) = opt {
427
+ //[no_feature]~^ ERROR `let` expressions in this position are unstable
354
428
}
355
429
356
430
let fun = || true ;
357
431
if let true = ( true && fun ( ) ) && ( true ) {
432
+ //[no_feature]~^ ERROR `let` expressions in this position are unstable
358
433
}
359
434
360
435
#[ cfg( FALSE ) ]
0 commit comments