]> git.lizzy.rs Git - rust.git/commitdiff
Eliminate an unwrap
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 30 Jan 2019 14:51:20 +0000 (15:51 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 30 Jan 2019 14:51:20 +0000 (15:51 +0100)
src/librustc_mir/interpret/eval_context.rs

index 4bf84cb465f7783538bd342564e19e310ceceb89..4e66d21214b29dd570f8ae338bc914bb1d4b2bd8 100644 (file)
@@ -320,17 +320,18 @@ pub fn layout_of_local(
         local: mir::Local,
         layout: Option<TyLayout<'tcx>>,
     ) -> EvalResult<'tcx, TyLayout<'tcx>> {
-        let cell = &frame.locals[local].layout;
-        if cell.get().is_none() {
-            let layout = ::interpret::operand::from_known_layout(layout, || {
-                let local_ty = frame.mir.local_decls[local].ty;
-                let local_ty = self.monomorphize_with_substs(local_ty, frame.instance.substs);
-                self.layout_of(local_ty)
-            })?;
-            cell.set(Some(layout));
+        match frame.locals[local].layout.get() {
+            None => {
+                let layout = ::interpret::operand::from_known_layout(layout, || {
+                    let local_ty = frame.mir.local_decls[local].ty;
+                    let local_ty = self.monomorphize_with_substs(local_ty, frame.instance.substs);
+                    self.layout_of(local_ty)
+                })?;
+                frame.locals[local].layout.set(Some(layout));
+                Ok(layout)
+            }
+            Some(layout) => Ok(layout),
         }
-
-        Ok(cell.get().unwrap())
     }
 
     pub fn str_to_immediate(&mut self, s: &str) -> EvalResult<'tcx, Immediate<M::PointerTag>> {