Skip to content

Commit 0b52710

Browse files
committed
Simplify force_allocation_maybe_sized
1 parent 6415539 commit 0b52710

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct LocalState<'tcx, Tag=(), Id=AllocId> {
121121
}
122122

123123
/// Current value of a local variable
124-
#[derive(Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
124+
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
125125
pub enum LocalValue<Tag=(), Id=AllocId> {
126126
/// This local is not currently alive, and cannot be used at all.
127127
Dead,

src/librustc_mir/interpret/place.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -984,30 +984,20 @@ where
984984
let (mplace, size) = match place.place {
985985
Place::Local { frame, local } => {
986986
match self.stack[frame].locals[local].access_mut()? {
987-
Ok(local_val) => {
987+
Ok(&mut local_val) => {
988988
// We need to make an allocation.
989-
// FIXME: Consider not doing anything for a ZST, and just returning
990-
// a fake pointer? Are we even called for ZST?
991-
992-
// We cannot hold on to the reference `local_val` while allocating,
993-
// but we can hold on to the value in there.
994-
let old_val =
995-
if let LocalValue::Live(Operand::Immediate(value)) = *local_val {
996-
Some(value)
997-
} else {
998-
None
999-
};
1000989

1001990
// We need the layout of the local. We can NOT use the layout we got,
1002991
// that might e.g., be an inner field of a struct with `Scalar` layout,
1003992
// that has different alignment than the outer field.
1004-
// We also need to support unsized types, and hence cannot use `allocate`.
1005993
let local_layout = self.layout_of_local(&self.stack[frame], local, None)?;
994+
995+
// We also need to support unsized types, and hence cannot use `allocate`.
1006996
let (size, align) = self.size_and_align_of(meta, local_layout)?
1007997
.expect("Cannot allocate for non-dyn-sized type");
1008998
let ptr = self.memory.allocate(size, align, MemoryKind::Stack);
1009999
let mplace = MemPlace { ptr: ptr.into(), align, meta };
1010-
if let Some(value) = old_val {
1000+
if let LocalValue::Live(Operand::Immediate(value)) = local_val {
10111001
// Preserve old value.
10121002
// We don't have to validate as we can assume the local
10131003
// was already valid for its type.

0 commit comments

Comments
 (0)