@@ -275,17 +275,21 @@ fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, b
275
275
fn check_place < ' tcx > ( tcx : TyCtxt < ' tcx > , place : Place < ' tcx > , span : Span , body : & Body < ' tcx > , in_move : bool ) -> McfResult {
276
276
let mut cursor = place. projection . as_ref ( ) ;
277
277
278
+ if let [ proj_base] = cursor
279
+ && let ProjectionElem :: Field ( _, ty) = proj_base
280
+ && !is_ty_const_destruct ( tcx, * ty, body)
281
+ && in_move
282
+ {
283
+ return Err ( (
284
+ span,
285
+ "cannot drop locals with a non constant destructor in const fn" . into ( ) ,
286
+ ) ) ;
287
+ }
288
+
278
289
while let [ ref proj_base @ .., elem] = * cursor {
279
290
cursor = proj_base;
280
291
match elem {
281
- ProjectionElem :: Field ( _, ty) => {
282
- if !is_ty_const_destruct ( tcx, ty, body) && in_move {
283
- return Err ( (
284
- span,
285
- "cannot drop locals with a non constant destructor in const fn" . into ( ) ,
286
- ) ) ;
287
- }
288
-
292
+ ProjectionElem :: Field ( ..) => {
289
293
let base_ty = Place :: ty_from ( place. local , proj_base, body, tcx) . ty ;
290
294
if let Some ( def) = base_ty. ty_adt_def ( ) {
291
295
// No union field accesses in `const fn`
@@ -328,7 +332,7 @@ fn check_terminator<'tcx>(
328
332
"cannot drop locals with a non constant destructor in const fn" . into ( ) ,
329
333
) ) ;
330
334
}
331
- check_place ( tcx , * place , span , body , false )
335
+ Ok ( ( ) )
332
336
} ,
333
337
TerminatorKind :: SwitchInt { discr, targets : _ } => check_operand ( tcx, discr, span, body) ,
334
338
TerminatorKind :: GeneratorDrop | TerminatorKind :: Yield { .. } => {
0 commit comments