From 3b19c83c678a74a508fe874ac261a99121e51397 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Jul 2017 20:32:51 -0700 Subject: [PATCH] remove ad-hoc 'never' type check in read_lvalue --- src/lvalue.rs | 11 +++-------- tests/compile-fail/never_say_never.rs | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lvalue.rs b/src/lvalue.rs index 9fc01eb0384f..59f5dc8f4bbc 100644 --- a/src/lvalue.rs +++ b/src/lvalue.rs @@ -182,7 +182,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { /// Returns a value and (in case of a ByRef) if we are supposed to use aligned accesses. pub(super) fn eval_and_read_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Value> { - let ty = self.lvalue_ty(lvalue); // Shortcut for things like accessing a fat pointer's field, // which would otherwise (in the `eval_lvalue` path) require moving a `ByValPair` to memory // and returning an `Lvalue::Ptr` to it @@ -190,14 +189,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { return Ok(val); } let lvalue = self.eval_lvalue(lvalue)?; - self.read_lvalue(lvalue, ty) + self.read_lvalue(lvalue) } - pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>) -> EvalResult<'tcx, Value> { - if ty.is_never() { - return Err(EvalError::Unreachable); - } - + pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> EvalResult<'tcx, Value> { match lvalue { Lvalue::Ptr { ptr, extra, aligned } => { assert_eq!(extra, LvalueExtra::None); @@ -382,7 +377,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } Deref => { - let val = self.read_lvalue(base, base_ty)?; + let val = self.read_lvalue(base)?; let pointee_type = match base_ty.sty { ty::TyRawPtr(ref tam) | diff --git a/tests/compile-fail/never_say_never.rs b/tests/compile-fail/never_say_never.rs index 5d7e9fec62c2..3e80cb20b3fa 100644 --- a/tests/compile-fail/never_say_never.rs +++ b/tests/compile-fail/never_say_never.rs @@ -4,7 +4,7 @@ fn main() { let y = &5; let x: ! = unsafe { - *(y as *const _ as *const !) //~ ERROR entered unreachable code + *(y as *const _ as *const !) //~ ERROR tried to access a dead local variable }; f(x) }