Skip to content

Commit f9019ae

Browse files
committed
Simplify local accessors
1 parent 4ea4dd2 commit f9019ae

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/librustc_mir/interpret/eval_context.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc::mir::interpret::{
1717
GlobalId, Value, Pointer, PrimVal, PrimValKind,
1818
EvalError, EvalResult, EvalErrorKind, MemoryPointer,
1919
};
20+
use std::mem;
2021

2122
use super::{Place, PlaceExtra, Memory,
2223
HasMemory, MemoryKind,
@@ -1704,20 +1705,17 @@ impl<'mir, 'tcx> Frame<'mir, 'tcx> {
17041705
}
17051706
}
17061707

1707-
pub fn storage_live(&mut self, local: mir::Local) -> EvalResult<'tcx, Option<Value>> {
1708+
pub fn storage_live(&mut self, local: mir::Local) -> Option<Value> {
17081709
trace!("{:?} is now live", local);
17091710

1710-
let old = self.locals[local];
1711-
self.locals[local] = Some(Value::ByVal(PrimVal::Undef)); // StorageLive *always* kills the value that's currently stored
1712-
return Ok(old);
1711+
// StorageLive *always* kills the value that's currently stored
1712+
mem::replace(&mut self.locals[local], Some(Value::ByVal(PrimVal::Undef)))
17131713
}
17141714

17151715
/// Returns the old value of the local
1716-
pub fn storage_dead(&mut self, local: mir::Local) -> EvalResult<'tcx, Option<Value>> {
1716+
pub fn storage_dead(&mut self, local: mir::Local) -> Option<Value> {
17171717
trace!("{:?} is now dead", local);
17181718

1719-
let old = self.locals[local];
1720-
self.locals[local] = None;
1721-
return Ok(old);
1719+
self.locals[local].take()
17221720
}
17231721
}

src/librustc_mir/interpret/step.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
6969

7070
// Mark locals as alive
7171
StorageLive(local) => {
72-
let old_val = self.frame_mut().storage_live(local)?;
72+
let old_val = self.frame_mut().storage_live(local);
7373
self.deallocate_local(old_val)?;
7474
}
7575

7676
// Mark locals as dead
7777
StorageDead(local) => {
78-
let old_val = self.frame_mut().storage_dead(local)?;
78+
let old_val = self.frame_mut().storage_dead(local);
7979
self.deallocate_local(old_val)?;
8080
}
8181

0 commit comments

Comments
 (0)