]> git.lizzy.rs Git - rust.git/commitdiff
Simplify `force_allocation_maybe_sized`
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 13 Dec 2019 23:05:04 +0000 (00:05 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 26 Dec 2019 21:50:16 +0000 (22:50 +0100)
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/place.rs

index e8576b198dc24c9e8a027285f9cefd521adbc779..5ba9dcd3aa5c8484c9ce7e4e3c329524733919cc 100644 (file)
@@ -118,7 +118,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> {
 }
 
 /// Current value of a local variable
-#[derive(Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
+#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
 pub enum LocalValue<Tag = (), Id = AllocId> {
     /// This local is not currently alive, and cannot be used at all.
     Dead,
index a558f0671e182be498dff4a26e2471a3e2103a71..c46075699331f184d9c69820f8377856e95a3d71 100644 (file)
@@ -974,31 +974,20 @@ pub fn force_allocation_maybe_sized(
         let (mplace, size) = match place.place {
             Place::Local { frame, local } => {
                 match self.stack[frame].locals[local].access_mut()? {
-                    Ok(local_val) => {
+                    Ok(&mut local_val) => {
                         // We need to make an allocation.
-                        // FIXME: Consider not doing anything for a ZST, and just returning
-                        // a fake pointer?  Are we even called for ZST?
-
-                        // We cannot hold on to the reference `local_val` while allocating,
-                        // but we can hold on to the value in there.
-                        let old_val =
-                            if let LocalValue::Live(Operand::Immediate(value)) = *local_val {
-                                Some(value)
-                            } else {
-                                None
-                            };
 
                         // We need the layout of the local.  We can NOT use the layout we got,
                         // that might e.g., be an inner field of a struct with `Scalar` layout,
                         // that has different alignment than the outer field.
-                        // We also need to support unsized types, and hence cannot use `allocate`.
                         let local_layout = self.layout_of_local(&self.stack[frame], local, None)?;
+                        // We also need to support unsized types, and hence cannot use `allocate`.
                         let (size, align) = self
                             .size_and_align_of(meta, local_layout)?
                             .expect("Cannot allocate for non-dyn-sized type");
                         let ptr = self.memory.allocate(size, align, MemoryKind::Stack);
                         let mplace = MemPlace { ptr: ptr.into(), align, meta };
-                        if let Some(value) = old_val {
+                        if let LocalValue::Live(Operand::Immediate(value)) = local_val {
                             // Preserve old value.
                             // We don't have to validate as we can assume the local
                             // was already valid for its type.