Skip to content

Commit 8be7c54

Browse files
committed
Simplify force_allocation_maybe_sized
1 parent cc5cc67 commit 8be7c54

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

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

0 commit comments

Comments
 (0)