diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 48108b69a37..a660b145b3f 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -385,19 +385,17 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { (), ); - let ret = if let Ok(layout) = ecx.layout_of(body.return_ty().subst(tcx, substs)) { + let ret = ecx + .layout_of(body.return_ty().subst(tcx, substs)) + .ok() // Don't bother allocating memory for ZST types which have no values // or for large values. - if !layout.is_zst() && layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) { - // hopefully all types will allocate, since large types have already been removed, - // but check anyways - ecx.allocate(layout, MemoryKind::Stack).ok().map(Into::into) - } else { - None - } - } else { - None - }; + .filter(|ret_layout| { + !ret_layout.is_zst() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) + }) + // hopefully all types will allocate, since large types have already been removed + .and_then(|ret_layout| ecx.allocate(ret_layout, MemoryKind::Stack).ok()) + .map(Into::into); ecx.push_stack_frame( Instance::new(def_id, substs),