Skip to content

Commit b40f3c1

Browse files
committed
Simplify const_prop logic
1 parent 524e575 commit b40f3c1

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,17 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
385385
(),
386386
);
387387

388-
let ret = if let Ok(layout) = ecx.layout_of(body.return_ty().subst(tcx, substs)) {
388+
let ret = ecx
389+
.layout_of(body.return_ty().subst(tcx, substs))
390+
.ok()
389391
// Don't bother allocating memory for ZST types which have no values
390392
// or for large values.
391-
if !layout.is_zst() && layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) {
392-
// hopefully all types will allocate, since large types have already been removed,
393-
// but check anyways
394-
ecx.allocate(layout, MemoryKind::Stack).ok().map(Into::into)
395-
} else {
396-
None
397-
}
398-
} else {
399-
None
400-
};
393+
.filter(|ret_layout| {
394+
!ret_layout.is_zst() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT)
395+
})
396+
// hopefully all types will allocate, since large types have already been removed
397+
.and_then(|ret_layout| ecx.allocate(ret_layout, MemoryKind::Stack).ok())
398+
.map(Into::into);
401399

402400
ecx.push_stack_frame(
403401
Instance::new(def_id, substs),

0 commit comments

Comments
 (0)