Skip to content

Commit a5503a3

Browse files
authored
Merge pull request rust-lang#350 from RalfJung/inhabited
get rid of ad-hoc inhabitedness test
2 parents 728e664 + 1ad9709 commit a5503a3

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

src/librustc_mir/interpret/eval_context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
18181818
let val = match val {
18191819
PrimVal::Bytes(0) => false,
18201820
PrimVal::Bytes(1) => true,
1821-
// TODO: This seems a little overeager, should reading at bool type already be UB?
1821+
// TODO: This seems a little overeager, should reading at bool type already be insta-UB?
18221822
_ => return err!(InvalidBool),
18231823
};
18241824
PrimVal::from_bool(val)
@@ -2237,10 +2237,6 @@ impl IntegerExt for layout::Integer {
22372237
}
22382238
}
22392239

2240-
pub fn is_inhabited<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
2241-
ty.uninhabited_from(&mut HashMap::default(), tcx).is_empty()
2242-
}
2243-
22442240
/// FIXME: expose trans::monomorphize::resolve_closure
22452241
pub fn resolve_closure<'a, 'tcx>(
22462242
tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/librustc_mir/interpret/terminator/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
251251
_ => return err!(Unreachable),
252252
};
253253
let ty = sig.output();
254-
if !eval_context::is_inhabited(self.tcx, ty) {
255-
return err!(Unreachable);
256-
}
257254
let layout = self.type_layout(ty)?;
258255
M::call_intrinsic(self, instance, args, ret, ty, layout, target)?;
259256
self.dump_local(ret);

tests/compile-fail/never_say_never.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This should fail even without validation
2+
// compile-flags: -Zmir-emit-validate=0
3+
14
#![feature(never_type)]
25
#![allow(unreachable_code)]
36

tests/compile-fail/never_transmute_humans.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This should fail even without validation
2+
// compile-flags: -Zmir-emit-validate=0
3+
14
#![feature(never_type)]
25
#![allow(unreachable_code)]
36
#![allow(unused_variables)]
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
// This should fail even without validation
2+
// compile-flags: -Zmir-emit-validate=0
3+
14
#![feature(never_type)]
25
#![allow(unreachable_code)]
36
#![allow(unused_variables)]
47

58
enum Void {}
69

710
fn f(v: Void) -> ! {
8-
match v {}
11+
match v {} //~ ERROR entered unreachable code
912
}
1013

1114
fn main() {
1215
let v: Void = unsafe {
13-
std::mem::transmute::<(), Void>(()) //~ ERROR entered unreachable code
16+
std::mem::transmute::<(), Void>(())
1417
};
1518
f(v);
1619
}

0 commit comments

Comments
 (0)