Skip to content

Commit e79bb42

Browse files
authored
Merge pull request #262 from RalfJung/never
remove ad-hoc 'never' type check in read_lvalue
2 parents f02d9e6 + 3b19c83 commit e79bb42

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/lvalue.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
182182

183183
/// Returns a value and (in case of a ByRef) if we are supposed to use aligned accesses.
184184
pub(super) fn eval_and_read_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Value> {
185-
let ty = self.lvalue_ty(lvalue);
186185
// Shortcut for things like accessing a fat pointer's field,
187186
// which would otherwise (in the `eval_lvalue` path) require moving a `ByValPair` to memory
188187
// and returning an `Lvalue::Ptr` to it
189188
if let Some(val) = self.try_read_lvalue(lvalue)? {
190189
return Ok(val);
191190
}
192191
let lvalue = self.eval_lvalue(lvalue)?;
193-
self.read_lvalue(lvalue, ty)
192+
self.read_lvalue(lvalue)
194193
}
195194

196-
pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>) -> EvalResult<'tcx, Value> {
197-
if ty.is_never() {
198-
return Err(EvalError::Unreachable);
199-
}
200-
195+
pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> EvalResult<'tcx, Value> {
201196
match lvalue {
202197
Lvalue::Ptr { ptr, extra, aligned } => {
203198
assert_eq!(extra, LvalueExtra::None);
@@ -382,7 +377,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
382377
}
383378

384379
Deref => {
385-
let val = self.read_lvalue(base, base_ty)?;
380+
let val = self.read_lvalue(base)?;
386381

387382
let pointee_type = match base_ty.sty {
388383
ty::TyRawPtr(ref tam) |

tests/compile-fail/never_say_never.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fn main() {
55
let y = &5;
66
let x: ! = unsafe {
7-
*(y as *const _ as *const !) //~ ERROR entered unreachable code
7+
*(y as *const _ as *const !) //~ ERROR tried to access a dead local variable
88
};
99
f(x)
1010
}

0 commit comments

Comments
 (0)