Skip to content

Commit bb1ecee

Browse files
committed
Simplify force_allocation_maybe_sized
1 parent b5b5258 commit bb1ecee

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/librustc_mir/interpret/eval_context.rs

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

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

src/librustc_mir/interpret/place.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -974,31 +974,20 @@ where
974974
let (mplace, size) = match place.place {
975975
Place::Local { frame, local } => {
976976
match self.stack[frame].locals[local].access_mut()? {
977-
Ok(local_val) => {
977+
Ok(&mut local_val) => {
978978
// We need to make an allocation.
979-
// FIXME: Consider not doing anything for a ZST, and just returning
980-
// a fake pointer? Are we even called for ZST?
981-
982-
// We cannot hold on to the reference `local_val` while allocating,
983-
// but we can hold on to the value in there.
984-
let old_val =
985-
if let LocalValue::Live(Operand::Immediate(value)) = *local_val {
986-
Some(value)
987-
} else {
988-
None
989-
};
990979

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

0 commit comments

Comments
 (0)