]> git.lizzy.rs Git - rust.git/commitdiff
get rid of ad-hoc inhabitedness test
authorRalf Jung <post@ralfj.de>
Fri, 22 Sep 2017 11:21:30 +0000 (13:21 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 22 Sep 2017 11:24:55 +0000 (13:24 +0200)
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/terminator/mod.rs
tests/compile-fail/never_say_never.rs
tests/compile-fail/never_transmute_humans.rs
tests/compile-fail/never_transmute_void.rs

index 8fb63b3cb2ca4c79763d80ac603f1d7328fcb5f7..0d761c245936cdb005fe5bd2a6889fef5c61017a 100644 (file)
@@ -1818,7 +1818,7 @@ fn try_read_value(&self, ptr: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx, Option<
                 let val = match val {
                     PrimVal::Bytes(0) => false,
                     PrimVal::Bytes(1) => true,
-                    // TODO: This seems a little overeager, should reading at bool type already be UB?
+                    // TODO: This seems a little overeager, should reading at bool type already be insta-UB?
                     _ => return err!(InvalidBool),
                 };
                 PrimVal::from_bool(val)
@@ -2237,10 +2237,6 @@ fn size(self) -> Size {
     }
 }
 
-pub fn is_inhabited<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
-    ty.uninhabited_from(&mut HashMap::default(), tcx).is_empty()
-}
-
 /// FIXME: expose trans::monomorphize::resolve_closure
 pub fn resolve_closure<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
index bee0fe23f7ff20e22ae6193c20577d109c22d3a5..e01777cdb4e76f1d275a5950faa1965758525b15 100644 (file)
@@ -251,9 +251,6 @@ fn eval_fn_call(
                     _ => return err!(Unreachable),
                 };
                 let ty = sig.output();
-                if !eval_context::is_inhabited(self.tcx, ty) {
-                    return err!(Unreachable);
-                }
                 let layout = self.type_layout(ty)?;
                 M::call_intrinsic(self, instance, args, ret, ty, layout, target)?;
                 self.dump_local(ret);
index 3e80cb20b3fa7127b51cfdb346ff0cab6464c772..6aa4e281818cabc41d7595bb2245c42802b3213b 100644 (file)
@@ -1,3 +1,6 @@
+// This should fail even without validation
+// compile-flags: -Zmir-emit-validate=0
+
 #![feature(never_type)]
 #![allow(unreachable_code)]
 
index 38406eeb3fea61a1d651988535aa5db0c1c8e71a..7390596cf7fa62f7fd524338c74ed2ebbaab67b5 100644 (file)
@@ -1,3 +1,6 @@
+// This should fail even without validation
+// compile-flags: -Zmir-emit-validate=0
+
 #![feature(never_type)]
 #![allow(unreachable_code)]
 #![allow(unused_variables)]
index 3fffacc55ea4773898b66410d38f16ecc9758f55..0b0897644409e1e5e2e3bedb0c2e3ca04254c239 100644 (file)
@@ -1,3 +1,6 @@
+// This should fail even without validation
+// compile-flags: -Zmir-emit-validate=0
+
 #![feature(never_type)]
 #![allow(unreachable_code)]
 #![allow(unused_variables)]
@@ -5,12 +8,12 @@
 enum Void {}
 
 fn f(v: Void) -> ! {
-    match v {}
+    match v {} //~ ERROR entered unreachable code
 }
 
 fn main() {
     let v: Void = unsafe {
-        std::mem::transmute::<(), Void>(()) //~ ERROR entered unreachable code
+        std::mem::transmute::<(), Void>(())
     };
     f(v);
 }