@@ -104,6 +104,10 @@ fn recurse_build<'tcx>(
104
104
) -> Result < ty:: Const < ' tcx > , ErrorGuaranteed > {
105
105
use thir:: ExprKind ;
106
106
let node = & body. exprs [ node] ;
107
+
108
+ let maybe_supported_error = |a| maybe_supported_error ( tcx, a, root_span) ;
109
+ let error = |a| error ( tcx, a, root_span) ;
110
+
107
111
Ok ( match & node. kind {
108
112
// I dont know if handling of these 3 is correct
109
113
& ExprKind :: Scope { value, .. } => recurse_build ( tcx, body, value, root_span) ?,
@@ -167,11 +171,7 @@ fn recurse_build<'tcx>(
167
171
if let thir:: Block { stmts : box [ ] , expr : Some ( e) , .. } = & body. blocks [ * block] {
168
172
recurse_build ( tcx, body, * e, root_span) ?
169
173
} else {
170
- maybe_supported_error (
171
- tcx,
172
- GenericConstantTooComplexSub :: BlockNotSupported ( node. span ) ,
173
- root_span,
174
- ) ?
174
+ maybe_supported_error ( GenericConstantTooComplexSub :: BlockNotSupported ( node. span ) ) ?
175
175
}
176
176
}
177
177
// `ExprKind::Use` happens when a `hir::ExprKind::Cast` is a
@@ -194,98 +194,74 @@ fn recurse_build<'tcx>(
194
194
if let ExprKind :: Deref { arg } = arg_node. kind {
195
195
recurse_build ( tcx, body, arg, root_span) ?
196
196
} else {
197
- maybe_supported_error (
198
- tcx,
199
- GenericConstantTooComplexSub :: BorrowNotSupported ( node. span ) ,
200
- root_span,
201
- ) ?
197
+ maybe_supported_error ( GenericConstantTooComplexSub :: BorrowNotSupported ( node. span ) ) ?
202
198
}
203
199
}
204
200
// FIXME(generic_const_exprs): We may want to support these.
205
201
ExprKind :: AddressOf { .. } | ExprKind :: Deref { .. } => maybe_supported_error (
206
- tcx,
207
202
GenericConstantTooComplexSub :: AddressAndDerefNotSupported ( node. span ) ,
208
- root_span,
209
- ) ?,
210
- ExprKind :: Repeat { .. } | ExprKind :: Array { .. } => maybe_supported_error (
211
- tcx,
212
- GenericConstantTooComplexSub :: ArrayNotSupported ( node. span ) ,
213
- root_span,
214
- ) ?,
215
- ExprKind :: NeverToAny { .. } => maybe_supported_error (
216
- tcx,
217
- GenericConstantTooComplexSub :: NeverToAnyNotSupported ( node. span ) ,
218
- root_span,
219
- ) ?,
220
- ExprKind :: Tuple { .. } => maybe_supported_error (
221
- tcx,
222
- GenericConstantTooComplexSub :: TupleNotSupported ( node. span ) ,
223
- root_span,
224
- ) ?,
225
- ExprKind :: Index { .. } => maybe_supported_error (
226
- tcx,
227
- GenericConstantTooComplexSub :: IndexNotSupported ( node. span ) ,
228
- root_span,
229
- ) ?,
230
- ExprKind :: Field { .. } => maybe_supported_error (
231
- tcx,
232
- GenericConstantTooComplexSub :: FieldNotSupported ( node. span ) ,
233
- root_span,
234
- ) ?,
235
- ExprKind :: ConstBlock { .. } => maybe_supported_error (
236
- tcx,
237
- GenericConstantTooComplexSub :: ConstBlockNotSupported ( node. span ) ,
238
- root_span,
239
- ) ?,
240
- ExprKind :: Adt ( _) => maybe_supported_error (
241
- tcx,
242
- GenericConstantTooComplexSub :: AdtNotSupported ( node. span ) ,
243
- root_span,
244
203
) ?,
204
+ ExprKind :: Repeat { .. } | ExprKind :: Array { .. } => {
205
+ maybe_supported_error ( GenericConstantTooComplexSub :: ArrayNotSupported ( node. span ) ) ?
206
+ }
207
+ ExprKind :: NeverToAny { .. } => {
208
+ maybe_supported_error ( GenericConstantTooComplexSub :: NeverToAnyNotSupported ( node. span ) ) ?
209
+ }
210
+ ExprKind :: Tuple { .. } => {
211
+ maybe_supported_error ( GenericConstantTooComplexSub :: TupleNotSupported ( node. span ) ) ?
212
+ }
213
+ ExprKind :: Index { .. } => {
214
+ maybe_supported_error ( GenericConstantTooComplexSub :: IndexNotSupported ( node. span ) ) ?
215
+ }
216
+ ExprKind :: Field { .. } => {
217
+ maybe_supported_error ( GenericConstantTooComplexSub :: FieldNotSupported ( node. span ) ) ?
218
+ }
219
+ ExprKind :: ConstBlock { .. } => {
220
+ maybe_supported_error ( GenericConstantTooComplexSub :: ConstBlockNotSupported ( node. span ) ) ?
221
+ }
222
+ ExprKind :: Adt ( _) => {
223
+ maybe_supported_error ( GenericConstantTooComplexSub :: AdtNotSupported ( node. span ) ) ?
224
+ }
245
225
// dont know if this is correct
246
226
ExprKind :: Pointer { .. } => {
247
- error ( tcx , GenericConstantTooComplexSub :: PointerNotSupported ( node. span ) , root_span ) ?
227
+ error ( GenericConstantTooComplexSub :: PointerNotSupported ( node. span ) ) ?
248
228
}
249
229
ExprKind :: Yield { .. } => {
250
- error ( tcx , GenericConstantTooComplexSub :: YieldNotSupported ( node. span ) , root_span ) ?
230
+ error ( GenericConstantTooComplexSub :: YieldNotSupported ( node. span ) ) ?
251
231
}
252
232
ExprKind :: Continue { .. } | ExprKind :: Break { .. } | ExprKind :: Loop { .. } => {
253
- error ( tcx, GenericConstantTooComplexSub :: LoopNotSupported ( node. span ) , root_span) ?
254
- }
255
- ExprKind :: Box { .. } => {
256
- error ( tcx, GenericConstantTooComplexSub :: BoxNotSupported ( node. span ) , root_span) ?
233
+ error ( GenericConstantTooComplexSub :: LoopNotSupported ( node. span ) ) ?
257
234
}
235
+ ExprKind :: Box { .. } => error ( GenericConstantTooComplexSub :: BoxNotSupported ( node. span ) ) ?,
258
236
259
237
ExprKind :: Unary { .. } => unreachable ! ( ) ,
260
238
// we handle valid unary/binary ops above
261
239
ExprKind :: Binary { .. } => {
262
- error ( tcx , GenericConstantTooComplexSub :: BinaryNotSupported ( node. span ) , root_span ) ?
240
+ error ( GenericConstantTooComplexSub :: BinaryNotSupported ( node. span ) ) ?
263
241
}
264
242
ExprKind :: LogicalOp { .. } => {
265
- error ( tcx , GenericConstantTooComplexSub :: LogicalOpNotSupported ( node. span ) , root_span ) ?
243
+ error ( GenericConstantTooComplexSub :: LogicalOpNotSupported ( node. span ) ) ?
266
244
}
267
245
ExprKind :: Assign { .. } | ExprKind :: AssignOp { .. } => {
268
- error ( tcx, GenericConstantTooComplexSub :: AssignNotSupported ( node. span ) , root_span) ?
246
+ error ( GenericConstantTooComplexSub :: AssignNotSupported ( node. span ) ) ?
247
+ }
248
+ ExprKind :: Closure { .. } | ExprKind :: Return { .. } => {
249
+ error ( GenericConstantTooComplexSub :: ClosureAndReturnNotSupported ( node. span ) ) ?
269
250
}
270
- ExprKind :: Closure { .. } | ExprKind :: Return { .. } => error (
271
- tcx,
272
- GenericConstantTooComplexSub :: ClosureAndReturnNotSupported ( node. span ) ,
273
- root_span,
274
- ) ?,
275
251
// let expressions imply control flow
276
252
ExprKind :: Match { .. } | ExprKind :: If { .. } | ExprKind :: Let { .. } => {
277
- error ( tcx , GenericConstantTooComplexSub :: ControlFlowNotSupported ( node. span ) , root_span ) ?
253
+ error ( GenericConstantTooComplexSub :: ControlFlowNotSupported ( node. span ) ) ?
278
254
}
279
255
ExprKind :: InlineAsm { .. } => {
280
- error ( tcx , GenericConstantTooComplexSub :: InlineAsmNotSupported ( node. span ) , root_span ) ?
256
+ error ( GenericConstantTooComplexSub :: InlineAsmNotSupported ( node. span ) ) ?
281
257
}
282
258
283
259
// we dont permit let stmts so `VarRef` and `UpvarRef` cant happen
284
260
ExprKind :: VarRef { .. }
285
261
| ExprKind :: UpvarRef { .. }
286
262
| ExprKind :: StaticRef { .. }
287
263
| ExprKind :: ThreadLocalRef ( _) => {
288
- error ( tcx , GenericConstantTooComplexSub :: OperationNotSupported ( node. span ) , root_span ) ?
264
+ error ( GenericConstantTooComplexSub :: OperationNotSupported ( node. span ) ) ?
289
265
}
290
266
} )
291
267
}
0 commit comments