@@ -104,6 +104,10 @@ fn recurse_build<'tcx>(
104104) -> Result < ty:: Const < ' tcx > , ErrorGuaranteed > {
105105 use thir:: ExprKind ;
106106 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+
107111 Ok ( match & node. kind {
108112 // I dont know if handling of these 3 is correct
109113 & ExprKind :: Scope { value, .. } => recurse_build ( tcx, body, value, root_span) ?,
@@ -167,11 +171,7 @@ fn recurse_build<'tcx>(
167171 if let thir:: Block { stmts : box [ ] , expr : Some ( e) , .. } = & body. blocks [ * block] {
168172 recurse_build ( tcx, body, * e, root_span) ?
169173 } else {
170- maybe_supported_error (
171- tcx,
172- GenericConstantTooComplexSub :: BlockNotSupported ( node. span ) ,
173- root_span,
174- ) ?
174+ maybe_supported_error ( GenericConstantTooComplexSub :: BlockNotSupported ( node. span ) ) ?
175175 }
176176 }
177177 // `ExprKind::Use` happens when a `hir::ExprKind::Cast` is a
@@ -194,98 +194,74 @@ fn recurse_build<'tcx>(
194194 if let ExprKind :: Deref { arg } = arg_node. kind {
195195 recurse_build ( tcx, body, arg, root_span) ?
196196 } else {
197- maybe_supported_error (
198- tcx,
199- GenericConstantTooComplexSub :: BorrowNotSupported ( node. span ) ,
200- root_span,
201- ) ?
197+ maybe_supported_error ( GenericConstantTooComplexSub :: BorrowNotSupported ( node. span ) ) ?
202198 }
203199 }
204200 // FIXME(generic_const_exprs): We may want to support these.
205201 ExprKind :: AddressOf { .. } | ExprKind :: Deref { .. } => maybe_supported_error (
206- tcx,
207202 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,
244203 ) ?,
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+ }
245225 // dont know if this is correct
246226 ExprKind :: Pointer { .. } => {
247- error ( tcx , GenericConstantTooComplexSub :: PointerNotSupported ( node. span ) , root_span ) ?
227+ error ( GenericConstantTooComplexSub :: PointerNotSupported ( node. span ) ) ?
248228 }
249229 ExprKind :: Yield { .. } => {
250- error ( tcx , GenericConstantTooComplexSub :: YieldNotSupported ( node. span ) , root_span ) ?
230+ error ( GenericConstantTooComplexSub :: YieldNotSupported ( node. span ) ) ?
251231 }
252232 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 ) ) ?
257234 }
235+ ExprKind :: Box { .. } => error ( GenericConstantTooComplexSub :: BoxNotSupported ( node. span ) ) ?,
258236
259237 ExprKind :: Unary { .. } => unreachable ! ( ) ,
260238 // we handle valid unary/binary ops above
261239 ExprKind :: Binary { .. } => {
262- error ( tcx , GenericConstantTooComplexSub :: BinaryNotSupported ( node. span ) , root_span ) ?
240+ error ( GenericConstantTooComplexSub :: BinaryNotSupported ( node. span ) ) ?
263241 }
264242 ExprKind :: LogicalOp { .. } => {
265- error ( tcx , GenericConstantTooComplexSub :: LogicalOpNotSupported ( node. span ) , root_span ) ?
243+ error ( GenericConstantTooComplexSub :: LogicalOpNotSupported ( node. span ) ) ?
266244 }
267245 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 ) ) ?
269250 }
270- ExprKind :: Closure { .. } | ExprKind :: Return { .. } => error (
271- tcx,
272- GenericConstantTooComplexSub :: ClosureAndReturnNotSupported ( node. span ) ,
273- root_span,
274- ) ?,
275251 // let expressions imply control flow
276252 ExprKind :: Match { .. } | ExprKind :: If { .. } | ExprKind :: Let { .. } => {
277- error ( tcx , GenericConstantTooComplexSub :: ControlFlowNotSupported ( node. span ) , root_span ) ?
253+ error ( GenericConstantTooComplexSub :: ControlFlowNotSupported ( node. span ) ) ?
278254 }
279255 ExprKind :: InlineAsm { .. } => {
280- error ( tcx , GenericConstantTooComplexSub :: InlineAsmNotSupported ( node. span ) , root_span ) ?
256+ error ( GenericConstantTooComplexSub :: InlineAsmNotSupported ( node. span ) ) ?
281257 }
282258
283259 // we dont permit let stmts so `VarRef` and `UpvarRef` cant happen
284260 ExprKind :: VarRef { .. }
285261 | ExprKind :: UpvarRef { .. }
286262 | ExprKind :: StaticRef { .. }
287263 | ExprKind :: ThreadLocalRef ( _) => {
288- error ( tcx , GenericConstantTooComplexSub :: OperationNotSupported ( node. span ) , root_span ) ?
264+ error ( GenericConstantTooComplexSub :: OperationNotSupported ( node. span ) ) ?
289265 }
290266 } )
291267}
0 commit comments