1
- // Here we test that `ast_validation ` behaves correctly wrt. `let $pats = $expr` expressions.
1
+ // Here we test that `lowering ` behaves correctly wrt. `let $pats = $expr` expressions.
2
2
//
3
3
// We want to make sure that `let` is banned in situations other than:
4
4
//
@@ -30,17 +30,22 @@ fn main() {}
30
30
31
31
fn nested_within_if_expr ( ) {
32
32
if & let 0 = 0 { } //~ ERROR `let` expressions are not supported here
33
- //~^ ERROR `let` expressions only supported in `if`
33
+ //~^ ERROR mismatched types
34
34
35
35
if !let 0 = 0 { } //~ ERROR `let` expressions are not supported here
36
36
if * let 0 = 0 { } //~ ERROR `let` expressions are not supported here
37
+ //~^ ERROR type `bool` cannot be dereferenced
37
38
if -let 0 = 0 { } //~ ERROR `let` expressions are not supported here
39
+ //~^ ERROR cannot apply unary operator `-` to type `bool`
38
40
39
41
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
40
42
if let 0 = 0 ? { }
43
+ //~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
41
44
Ok ( ( ) )
42
45
}
43
46
if ( let 0 = 0 ) ? { } //~ ERROR `let` expressions are not supported here
47
+ //~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
48
+ //~| ERROR the `?` operator can only be used in a function that returns `Result`
44
49
45
50
if true || let 0 = 0 { } //~ ERROR `let` expressions are not supported here
46
51
if ( true || let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
@@ -49,42 +54,62 @@ fn nested_within_if_expr() {
49
54
50
55
let mut x = true ;
51
56
if x = let 0 = 0 { } //~ ERROR `let` expressions are not supported here
57
+ //~^ ERROR mismatched types
52
58
53
59
if true ..( let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
60
+ //~^ ERROR mismatched types
54
61
if ..( let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
62
+ //~^ ERROR mismatched types
55
63
if ( let 0 = 0 ) .. { } //~ ERROR `let` expressions are not supported here
64
+ //~^ ERROR mismatched types
56
65
57
66
// Binds as `(let ... = true)..true &&/|| false`.
58
67
if let Range { start : _, end : _ } = true ..true && false { }
59
68
//~^ ERROR `let` expressions are not supported here
69
+ //~| ERROR mismatched types
70
+ //~| ERROR mismatched types
60
71
if let Range { start : _, end : _ } = true ..true || false { }
61
72
//~^ ERROR `let` expressions are not supported here
73
+ //~| ERROR mismatched types
74
+ //~| ERROR mismatched types
62
75
63
76
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
64
77
const F : fn ( ) -> bool = || true ;
65
78
if let Range { start : F , end } = F ..|| true { }
66
79
//~^ ERROR `let` expressions are not supported here
80
+ //~| ERROR mismatched types
81
+ //~| ERROR mismatched types
82
+ //~| ERROR mismatched types
67
83
68
84
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
69
85
let t = & & true ;
70
86
if let Range { start : true , end } = t..&&false { }
71
87
//~^ ERROR `let` expressions are not supported here
88
+ //~| ERROR mismatched types
89
+ //~| ERROR mismatched types
90
+ //~| ERROR mismatched types
72
91
73
92
if let true = let true = true { } //~ ERROR `let` expressions are not supported here
74
93
}
75
94
76
95
fn nested_within_while_expr ( ) {
77
96
while & let 0 = 0 { } //~ ERROR `let` expressions are not supported here
97
+ //~^ ERROR mismatched types
78
98
79
99
while !let 0 = 0 { } //~ ERROR `let` expressions are not supported here
80
100
while * let 0 = 0 { } //~ ERROR `let` expressions are not supported here
101
+ //~^ ERROR type `bool` cannot be dereferenced
81
102
while -let 0 = 0 { } //~ ERROR `let` expressions are not supported here
103
+ //~^ ERROR cannot apply unary operator `-` to type `bool`
82
104
83
105
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
84
106
while let 0 = 0 ? { }
107
+ //~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
85
108
Ok ( ( ) )
86
109
}
87
110
while ( let 0 = 0 ) ? { } //~ ERROR `let` expressions are not supported here
111
+ //~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
112
+ //~| ERROR the `?` operator can only be used in a function that returns `Result`
88
113
89
114
while true || let 0 = 0 { } //~ ERROR `let` expressions are not supported here
90
115
while ( true || let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
@@ -93,26 +118,40 @@ fn nested_within_while_expr() {
93
118
94
119
let mut x = true ;
95
120
while x = let 0 = 0 { } //~ ERROR `let` expressions are not supported here
121
+ //~^ ERROR mismatched types
96
122
97
123
while true ..( let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
124
+ //~^ ERROR mismatched types
98
125
while ..( let 0 = 0 ) { } //~ ERROR `let` expressions are not supported here
126
+ //~^ ERROR mismatched types
99
127
while ( let 0 = 0 ) .. { } //~ ERROR `let` expressions are not supported here
128
+ //~^ ERROR mismatched types
100
129
101
130
// Binds as `(let ... = true)..true &&/|| false`.
102
131
while let Range { start : _, end : _ } = true ..true && false { }
103
132
//~^ ERROR `let` expressions are not supported here
133
+ //~| ERROR mismatched types
134
+ //~| ERROR mismatched types
104
135
while let Range { start : _, end : _ } = true ..true || false { }
105
136
//~^ ERROR `let` expressions are not supported here
137
+ //~| ERROR mismatched types
138
+ //~| ERROR mismatched types
106
139
107
140
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
108
141
const F : fn ( ) -> bool = || true ;
109
142
while let Range { start : F , end } = F ..|| true { }
110
143
//~^ ERROR `let` expressions are not supported here
144
+ //~| ERROR mismatched types
145
+ //~| ERROR mismatched types
146
+ //~| ERROR mismatched types
111
147
112
148
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
113
149
let t = & & true ;
114
150
while let Range { start : true , end } = t..&&false { }
115
151
//~^ ERROR `let` expressions are not supported here
152
+ //~| ERROR mismatched types
153
+ //~| ERROR mismatched types
154
+ //~| ERROR mismatched types
116
155
117
156
while let true = let true = true { } //~ ERROR `let` expressions are not supported here
118
157
}
@@ -132,13 +171,18 @@ fn outside_if_and_while_expr() {
132
171
133
172
!let 0 = 0 ; //~ ERROR `let` expressions are not supported here
134
173
* let 0 = 0 ; //~ ERROR `let` expressions are not supported here
174
+ //~^ ERROR type `bool` cannot be dereferenced
135
175
-let 0 = 0 ; //~ ERROR `let` expressions are not supported here
176
+ //~^ ERROR cannot apply unary operator `-` to type `bool`
136
177
137
178
fn _check_try_binds_tighter ( ) -> Result < ( ) , ( ) > {
138
179
let 0 = 0 ?;
180
+ //~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
139
181
Ok ( ( ) )
140
182
}
141
183
( let 0 = 0 ) ?; //~ ERROR `let` expressions are not supported here
184
+ //~^ ERROR the `?` operator can only be used in a function that returns `Result`
185
+ //~| ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
142
186
143
187
true || let 0 = 0 ; //~ ERROR `let` expressions are not supported here
144
188
( true || let 0 = 0 ) ; //~ ERROR `let` expressions are not supported here
@@ -153,6 +197,7 @@ fn outside_if_and_while_expr() {
153
197
154
198
( let Range { start : _, end : _ } = true ..true || false ) ;
155
199
//~^ ERROR `let` expressions are not supported here
200
+ //~| ERROR mismatched types
156
201
157
202
( let true = let true = true ) ;
158
203
//~^ ERROR `let` expressions are not supported here
@@ -161,6 +206,7 @@ fn outside_if_and_while_expr() {
161
206
// Check function tail position.
162
207
& let 0 = 0
163
208
//~^ ERROR `let` expressions are not supported here
209
+ //~| ERROR mismatched types
164
210
}
165
211
166
212
// Let's make sure that `let` inside const generic arguments are considered.
@@ -170,14 +216,20 @@ fn inside_const_generic_arguments() {
170
216
171
217
if let A :: < {
172
218
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
219
+ //~^ ERROR constant contains unimplemented expression type
220
+ //~| ERROR constant contains unimplemented expression type
173
221
} > :: O = 5 { }
174
222
175
223
while let A :: < {
176
224
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
225
+ //~^ ERROR constant contains unimplemented expression type
226
+ //~| ERROR constant contains unimplemented expression type
177
227
} > :: O = 5 { }
178
228
179
229
if A :: < {
180
230
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
231
+ //~^ ERROR constant contains unimplemented expression type
232
+ //~| ERROR constant contains unimplemented expression type
181
233
} > :: O == 5 { }
182
234
183
235
// In the cases above we have `ExprKind::Block` to help us out.
0 commit comments