Skip to content

Commit fd32fe9

Browse files
committedAug 12, 2020
fix span of stack size error
1 parent a505e77 commit fd32fe9

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed
 

Diff for: ‎src/librustc_mir/const_eval/machine.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
301301
Ok(())
302302
}
303303

304-
fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
305-
// Enforce stack size limit.
306-
if !ecx.tcx.sess.recursion_limit().value_within_limit(ecx.stack().len()) {
304+
#[inline(always)]
305+
fn init_frame_extra(
306+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
307+
frame: Frame<'mir, 'tcx>,
308+
) -> InterpResult<'tcx, Frame<'mir, 'tcx>> {
309+
// Enforce stack size limit. Add 1 because this is run before the new frame is pushed.
310+
if !ecx.tcx.sess.recursion_limit().value_within_limit(ecx.stack().len() + 1) {
307311
throw_exhaust!(StackFrameLimitReached)
308312
} else {
309-
Ok(())
313+
Ok(frame)
310314
}
311315
}
312316

Diff for: ‎src/librustc_mir/interpret/machine.rs

-8
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,4 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
409409
) -> Self::PointerTag {
410410
()
411411
}
412-
413-
#[inline(always)]
414-
fn init_frame_extra(
415-
_ecx: &mut InterpCx<$mir, $tcx, Self>,
416-
frame: Frame<$mir, $tcx>,
417-
) -> InterpResult<$tcx, Frame<$mir, $tcx>> {
418-
Ok(frame)
419-
}
420412
}

Diff for: ‎src/librustc_mir/transform/const_prop.rs

+8
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
281281
Ok(())
282282
}
283283

284+
#[inline(always)]
285+
fn init_frame_extra(
286+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
287+
frame: Frame<'mir, 'tcx>,
288+
) -> InterpResult<'tcx, Frame<'mir, 'tcx>> {
289+
Ok(frame)
290+
}
291+
284292
#[inline(always)]
285293
fn stack(
286294
ecx: &'a InterpCx<'mir, 'tcx, Self>,

Diff for: ‎src/test/ui/consts/uninhabited-const-issue-61744.rs

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

33
pub const unsafe fn fake_type<T>() -> T {
4-
hint_unreachable() //~ ERROR evaluation of constant value failed
4+
hint_unreachable()
55
}
66

77
pub const unsafe fn hint_unreachable() -> ! {
8-
fake_type()
8+
fake_type() //~ ERROR evaluation of constant value failed
99
}
1010

1111
trait Const {

Diff for: ‎src/test/ui/consts/uninhabited-const-issue-61744.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/uninhabited-const-issue-61744.rs:4:5
2+
--> $DIR/uninhabited-const-issue-61744.rs:8:5
33
|
44
LL | hint_unreachable()
5-
| ^^^^^^^^^^^^^^^^^^
5+
| ------------------
66
| |
7-
| reached the configured maximum number of stack frames
8-
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
97
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
108
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
119
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
@@ -72,8 +70,9 @@ LL | hint_unreachable()
7270
| inside `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:4:5
7371
...
7472
LL | fake_type()
75-
| -----------
73+
| ^^^^^^^^^^^
7674
| |
75+
| reached the configured maximum number of stack frames
7776
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
7877
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
7978
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5

0 commit comments

Comments
 (0)
Please sign in to comment.