Skip to content

Commit 63b4709

Browse files
Rollup merge of #63433 - RalfJung:miri-call, r=oli-obk
Miri shouldn't look at types r? @oli-obk Fixes #62137
2 parents d941f97 + 62f1e8a commit 63b4709

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

src/librustc_mir/interpret/eval_context.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,19 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
385385
local: mir::Local,
386386
layout: Option<TyLayout<'tcx>>,
387387
) -> InterpResult<'tcx, TyLayout<'tcx>> {
388-
match frame.locals[local].layout.get() {
388+
// `const_prop` runs into this with an invalid (empty) frame, so we
389+
// have to support that case (mostly by skipping all caching).
390+
match frame.locals.get(local).and_then(|state| state.layout.get()) {
389391
None => {
390392
let layout = crate::interpret::operand::from_known_layout(layout, || {
391393
let local_ty = frame.body.local_decls[local].ty;
392394
let local_ty = self.monomorphize_with_substs(local_ty, frame.instance.substs)?;
393395
self.layout_of(local_ty)
394396
})?;
395-
// Layouts of locals are requested a lot, so we cache them.
396-
frame.locals[local].layout.set(Some(layout));
397+
if let Some(state) = frame.locals.get(local) {
398+
// Layouts of locals are requested a lot, so we cache them.
399+
state.layout.set(Some(layout));
400+
}
397401
Ok(layout)
398402
}
399403
Some(layout) => Ok(layout),

src/librustc_mir/interpret/terminator.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
405405
}
406406
} else {
407407
let local = mir::RETURN_PLACE;
408-
let ty = self.frame().body.local_decls[local].ty;
409-
if !self.tcx.is_ty_uninhabited_from_any_module(ty) {
410-
throw_unsup!(FunctionRetMismatch(self.tcx.types.never, ty))
408+
let callee_layout = self.layout_of_local(self.frame(), local, None)?;
409+
if !callee_layout.abi.is_uninhabited() {
410+
throw_unsup!(FunctionRetMismatch(
411+
self.tcx.types.never, callee_layout.ty
412+
))
411413
}
412414
}
413415
Ok(())

src/test/ui/consts/uninhabited-const-issue-61744.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// compile-fail
22

33
pub const unsafe fn fake_type<T>() -> T {
4-
hint_unreachable()
4+
hint_unreachable() //~ ERROR any use of this value will cause an error
55
}
66

77
pub const unsafe fn hint_unreachable() -> ! {
8-
fake_type() //~ ERROR any use of this value will cause an error
8+
fake_type()
99
}
1010

1111
trait Const {

src/test/ui/consts/uninhabited-const-issue-61744.stderr

+53-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
11
error: any use of this value will cause an error
2-
--> $DIR/uninhabited-const-issue-61744.rs:8:5
2+
--> $DIR/uninhabited-const-issue-61744.rs:4:5
33
|
4-
LL | fake_type()
5-
| ^^^^^^^^^^^
4+
LL | hint_unreachable()
5+
| ^^^^^^^^^^^^^^^^^^
66
| |
7-
| tried to call a function with return type T passing return place of type !
7+
| reached the configured maximum number of stack frames
88
| inside call to `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:4:5
9+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
10+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
11+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
12+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
13+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
14+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
15+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
16+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
17+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
18+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
19+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
20+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
21+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
22+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
23+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
24+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
25+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
26+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
27+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
28+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
29+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
30+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
31+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
32+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
33+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
34+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
35+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
36+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
37+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
38+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
39+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
40+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
41+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
42+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
43+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
44+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
45+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
46+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
47+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
48+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
49+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
50+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
51+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
52+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
53+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
54+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
55+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
56+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
57+
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5
958
| inside call to `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:12:36
1059
...
1160
LL | const CONSTANT: i32 = unsafe { fake_type() };

0 commit comments

Comments
 (0)