diff --git a/src/eval_context.rs b/src/eval_context.rs index 7696a70f379..0ae95d1b05a 100644 --- a/src/eval_context.rs +++ b/src/eval_context.rs @@ -774,7 +774,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { substs: substs, promoted: None, }; - self.read_lvalue(Lvalue::Global(cid))? + self.read_lvalue(Lvalue::Global(cid)) } } @@ -784,7 +784,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { substs: self.substs(), promoted: Some(index), }; - self.read_lvalue(Lvalue::Global(cid))? + self.read_lvalue(Lvalue::Global(cid)) } }; diff --git a/src/lvalue.rs b/src/lvalue.rs index 1ff526654ca..f06cffeee89 100644 --- a/src/lvalue.rs +++ b/src/lvalue.rs @@ -1,12 +1,13 @@ use rustc::hir::def_id::DefId; use rustc::mir; -use rustc::ty::{self, Ty}; use rustc::ty::subst::Substs; +use rustc::ty::{self, Ty}; use rustc_data_structures::indexed_vec::Idx; -use error::{EvalError, EvalResult}; +use error::EvalResult; +use eval_context::{EvalContext}; use memory::Pointer; -use eval_context::{EvalContext, Value}; +use value::{PrimVal, Value}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Lvalue<'tcx> { @@ -117,23 +118,25 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } } let lvalue = self.eval_lvalue(lvalue)?; - self.read_lvalue(lvalue) + Ok(self.read_lvalue(lvalue)) } - pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> EvalResult<'tcx, Value> { + pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> Value { match lvalue { Lvalue::Ptr { ptr, extra } => { assert_eq!(extra, LvalueExtra::None); - Ok(Value::ByRef(ptr)) + Value::ByRef(ptr) } Lvalue::Local { frame, local } => { - self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes) + self.stack[frame].get_local(local).unwrap_or(Value::ByVal(PrimVal::Undef)) + } + Lvalue::Global(cid) => { + self.globals + .get(&cid) + .expect("global not cached") + .data + .unwrap_or(Value::ByVal(PrimVal::Undef)) } - Lvalue::Global(cid) => self.globals - .get(&cid) - .expect("global not cached") - .data - .ok_or(EvalError::ReadUndefBytes), } } diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index b4cad215b77..9672b0c3d92 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -585,7 +585,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { match ty.sty { // special case `Box` to deallocate the inner allocation ty::TyBox(contents_ty) => { - let val = self.read_lvalue(lval)?; + let val = self.read_lvalue(lval); // we are going through the read_value path, because that already does all the // checks for the trait object types. We'd only be repeating ourselves here. let val = self.follow_by_ref_value(val, ty)?;