diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-25 17:15:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-25 17:15:29 +0200 |
| commit | d0e926fcfd6ca41eafd6e15900bc1004dfc81d6c (patch) | |
| tree | b8059a583dd38852abc7d667edbc01c3fa506858 | |
| parent | 40ab9d2bd57a2203131abd723f7120e960299fae (diff) | |
| parent | b7a0e401759505f39a07e9cb9421aa695b4856e9 (diff) | |
| download | rust-d0e926fcfd6ca41eafd6e15900bc1004dfc81d6c.tar.gz rust-d0e926fcfd6ca41eafd6e15900bc1004dfc81d6c.zip | |
Rollup merge of #61814 - varkor:uninhabited-const-61744, r=oli-obk
Fix an ICE with uninhabited consts Fixes https://github.com/rust-lang/rust/issues/61744. r? @oli-obk
| -rw-r--r-- | src/librustc/ty/inhabitedness/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/terminator.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/consts/uninhabited-const-issue-61744.rs | 19 | ||||
| -rw-r--r-- | src/test/ui/consts/uninhabited-const-issue-61744.stderr | 24 |
4 files changed, 48 insertions, 7 deletions
diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index 5ce750849f4..0d96e5ea625 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -97,7 +97,7 @@ impl<'tcx> TyCtxt<'tcx> { self.ty_inhabitedness_forest(ty).contains(self, module) } - pub fn is_ty_uninhabited_from_all_modules(self, ty: Ty<'tcx>) -> bool { + pub fn is_ty_uninhabited_from_any_module(self, ty: Ty<'tcx>) -> bool { !self.ty_inhabitedness_forest(ty).is_empty() } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index af061f96810..a29611e4814 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -388,12 +388,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { )); } } else { - let callee_layout = - self.layout_of_local(self.frame(), mir::RETURN_PLACE, None)?; - if !callee_layout.abi.is_uninhabited() { - return err!(FunctionRetMismatch( - self.tcx.types.never, callee_layout.ty - )); + let local = mir::RETURN_PLACE; + let ty = self.frame().body.local_decls[local].ty; + if !self.tcx.is_ty_uninhabited_from_any_module(ty) { + return err!(FunctionRetMismatch(self.tcx.types.never, ty)); } } Ok(()) diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.rs b/src/test/ui/consts/uninhabited-const-issue-61744.rs new file mode 100644 index 00000000000..21fbbf8cfb5 --- /dev/null +++ b/src/test/ui/consts/uninhabited-const-issue-61744.rs @@ -0,0 +1,19 @@ +// compile-fail + +pub const unsafe fn fake_type<T>() -> T { + hint_unreachable() +} + +pub const unsafe fn hint_unreachable() -> ! { + fake_type() //~ ERROR any use of this value will cause an error +} + +trait Const { + const CONSTANT: i32 = unsafe { fake_type() }; +} + +impl <T> Const for T {} + +pub fn main() -> () { + dbg!(i32::CONSTANT); //~ ERROR erroneous constant used +} diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.stderr b/src/test/ui/consts/uninhabited-const-issue-61744.stderr new file mode 100644 index 00000000000..5c285543711 --- /dev/null +++ b/src/test/ui/consts/uninhabited-const-issue-61744.stderr @@ -0,0 +1,24 @@ +error: any use of this value will cause an error + --> $DIR/uninhabited-const-issue-61744.rs:8:5 + | +LL | fake_type() + | ^^^^^^^^^^^ + | | + | tried to call a function with return type T passing return place of type ! + | inside call to `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:4:5 + | inside call to `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:12:36 +... +LL | const CONSTANT: i32 = unsafe { fake_type() }; + | --------------------------------------------- + | + = note: #[deny(const_err)] on by default + +error[E0080]: erroneous constant used + --> $DIR/uninhabited-const-issue-61744.rs:18:10 + | +LL | dbg!(i32::CONSTANT); + | ^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. |
