diff options
| author | Smitty <me@smitop.com> | 2021-06-15 17:57:54 -0400 |
|---|---|---|
| committer | Smitty <me@smitop.com> | 2021-06-29 19:08:29 -0400 |
| commit | b40f3c10609a6f456f9a7c81fa9d49e22c10e3bc (patch) | |
| tree | 25e91af8e2044810d4f1f7f07dc7ba6c2e232290 | |
| parent | 524e575bb40896cfa839baa03b08ae1fd70aded6 (diff) | |
| download | rust-b40f3c10609a6f456f9a7c81fa9d49e22c10e3bc.tar.gz rust-b40f3c10609a6f456f9a7c81fa9d49e22c10e3bc.zip | |
Simplify const_prop logic
| -rw-r--r-- | compiler/rustc_mir/src/transform/const_prop.rs | 20 |
1 files changed, 9 insertions, 11 deletions
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), |
