@@ -275,17 +275,21 @@ fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, b
275275fn check_place < ' tcx > ( tcx : TyCtxt < ' tcx > , place : Place < ' tcx > , span : Span , body : & Body < ' tcx > , in_move : bool ) -> McfResult {
276276 let mut cursor = place. projection . as_ref ( ) ;
277277
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+
278289 while let [ ref proj_base @ .., elem] = * cursor {
279290 cursor = proj_base;
280291 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 ( ..) => {
289293 let base_ty = Place :: ty_from ( place. local , proj_base, body, tcx) . ty ;
290294 if let Some ( def) = base_ty. ty_adt_def ( ) {
291295 // No union field accesses in `const fn`
@@ -328,7 +332,7 @@ fn check_terminator<'tcx>(
328332 "cannot drop locals with a non constant destructor in const fn" . into ( ) ,
329333 ) ) ;
330334 }
331- check_place ( tcx , * place , span , body , false )
335+ Ok ( ( ) )
332336 } ,
333337 TerminatorKind :: SwitchInt { discr, targets : _ } => check_operand ( tcx, discr, span, body) ,
334338 TerminatorKind :: GeneratorDrop | TerminatorKind :: Yield { .. } => {
0 commit comments