add method to ensure that a Value::ByRef is now a Value::ByVal*

This commit is contained in:
Oliver Schneider 2016-11-04 15:49:51 +01:00
parent 8003c570d8
commit 859b7049c8
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46

View File

@ -1115,13 +1115,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}
fn value_to_primval(&mut self, value: Value, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
/// ensures this Value is not a ByRef
fn follow_by_ref_value(&mut self, value: Value, ty: Ty<'tcx>) -> EvalResult<'tcx, Value> {
match value {
Value::ByRef(ptr) => match self.read_value(ptr, ty)? {
Value::ByRef(_) => bug!("read_value can't result in `ByRef`"),
Value::ByVal(primval) => Ok(primval),
Value::ByValPair(..) => bug!("value_to_primval can't work with fat pointers"),
},
Value::ByRef(ptr) => self.read_value(ptr, ty),
other => Ok(other),
}
}
fn value_to_primval(&mut self, value: Value, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
match self.follow_by_ref_value(value, ty)? {
Value::ByRef(_) => bug!("follow_by_ref_value can't result in `ByRef`"),
Value::ByVal(primval) => {
let new_primval = self.transmute_primval(primval, ty)?;