From 1ad9709e0032c2f3c37c4a156419cadb7e9c17ac Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Sep 2017 13:21:30 +0200 Subject: [PATCH] get rid of ad-hoc inhabitedness test --- src/librustc_mir/interpret/eval_context.rs | 6 +----- src/librustc_mir/interpret/terminator/mod.rs | 3 --- tests/compile-fail/never_say_never.rs | 3 +++ tests/compile-fail/never_transmute_humans.rs | 3 +++ tests/compile-fail/never_transmute_void.rs | 7 +++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 8fb63b3cb2ca4..0d761c245936c 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -1818,7 +1818,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { 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 @@ impl IntegerExt for layout::Integer { } } -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>, diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index bee0fe23f7ff2..e01777cdb4e76 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -251,9 +251,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { _ => 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); diff --git a/tests/compile-fail/never_say_never.rs b/tests/compile-fail/never_say_never.rs index 3e80cb20b3fa7..6aa4e281818ca 100644 --- a/tests/compile-fail/never_say_never.rs +++ b/tests/compile-fail/never_say_never.rs @@ -1,3 +1,6 @@ +// This should fail even without validation +// compile-flags: -Zmir-emit-validate=0 + #![feature(never_type)] #![allow(unreachable_code)] diff --git a/tests/compile-fail/never_transmute_humans.rs b/tests/compile-fail/never_transmute_humans.rs index 38406eeb3fea6..7390596cf7fa6 100644 --- a/tests/compile-fail/never_transmute_humans.rs +++ b/tests/compile-fail/never_transmute_humans.rs @@ -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)] diff --git a/tests/compile-fail/never_transmute_void.rs b/tests/compile-fail/never_transmute_void.rs index 3fffacc55ea47..0b0897644409e 100644 --- a/tests/compile-fail/never_transmute_void.rs +++ b/tests/compile-fail/never_transmute_void.rs @@ -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); }