@@ -275,18 +275,28 @@ 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 {
292
+ ProjectionElem :: Field ( ..) => {
293
+ let base_ty = Place :: ty_from ( place. local , proj_base, body, tcx) . ty ;
294
+ if !is_ty_const_destruct ( tcx, base_ty, body) && in_move {
283
295
return Err ( (
284
296
span,
285
297
"cannot drop locals with a non constant destructor in const fn" . into ( ) ,
286
298
) ) ;
287
299
}
288
-
289
- let base_ty = Place :: ty_from ( place. local , proj_base, body, tcx) . ty ;
290
300
if let Some ( def) = base_ty. ty_adt_def ( ) {
291
301
// No union field accesses in `const fn`
292
302
if def. is_union ( ) {
@@ -328,7 +338,7 @@ fn check_terminator<'tcx>(
328
338
"cannot drop locals with a non constant destructor in const fn" . into ( ) ,
329
339
) ) ;
330
340
}
331
- check_place ( tcx , * place , span , body , false )
341
+ Ok ( ( ) )
332
342
} ,
333
343
TerminatorKind :: SwitchInt { discr, targets : _ } => check_operand ( tcx, discr, span, body) ,
334
344
TerminatorKind :: GeneratorDrop | TerminatorKind :: Yield { .. } => {
0 commit comments