From fd32fe9bb9cc97a5a3d97ab0f6ab673d8c81fa88 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Aug 2020 10:18:21 +0200 Subject: [PATCH] fix span of stack size error --- src/librustc_mir/const_eval/machine.rs | 12 ++++++++---- src/librustc_mir/interpret/machine.rs | 8 -------- src/librustc_mir/transform/const_prop.rs | 8 ++++++++ src/test/ui/consts/uninhabited-const-issue-61744.rs | 4 ++-- .../ui/consts/uninhabited-const-issue-61744.stderr | 9 ++++----- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs index 3a753a0edb665..2d0e68d58943f 100644 --- a/src/librustc_mir/const_eval/machine.rs +++ b/src/librustc_mir/const_eval/machine.rs @@ -301,12 +301,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, Ok(()) } - fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { - // Enforce stack size limit. - if !ecx.tcx.sess.recursion_limit().value_within_limit(ecx.stack().len()) { + #[inline(always)] + fn init_frame_extra( + ecx: &mut InterpCx<'mir, 'tcx, Self>, + frame: Frame<'mir, 'tcx>, + ) -> InterpResult<'tcx, Frame<'mir, 'tcx>> { + // Enforce stack size limit. Add 1 because this is run before the new frame is pushed. + if !ecx.tcx.sess.recursion_limit().value_within_limit(ecx.stack().len() + 1) { throw_exhaust!(StackFrameLimitReached) } else { - Ok(()) + Ok(frame) } } diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 634f3c96e6c9f..5cab4ba37e3a5 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -409,12 +409,4 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) { ) -> Self::PointerTag { () } - - #[inline(always)] - fn init_frame_extra( - _ecx: &mut InterpCx<$mir, $tcx, Self>, - frame: Frame<$mir, $tcx>, - ) -> InterpResult<$tcx, Frame<$mir, $tcx>> { - Ok(frame) - } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 6cf296f2a3fda..3b39d5f66b78f 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -281,6 +281,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> Ok(()) } + #[inline(always)] + fn init_frame_extra( + _ecx: &mut InterpCx<'mir, 'tcx, Self>, + frame: Frame<'mir, 'tcx>, + ) -> InterpResult<'tcx, Frame<'mir, 'tcx>> { + Ok(frame) + } + #[inline(always)] fn stack( ecx: &'a InterpCx<'mir, 'tcx, Self>, diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.rs b/src/test/ui/consts/uninhabited-const-issue-61744.rs index 55f42d84f9cb0..15436f9c1b2cf 100644 --- a/src/test/ui/consts/uninhabited-const-issue-61744.rs +++ b/src/test/ui/consts/uninhabited-const-issue-61744.rs @@ -1,11 +1,11 @@ // build-fail pub const unsafe fn fake_type() -> T { - hint_unreachable() //~ ERROR evaluation of constant value failed + hint_unreachable() } pub const unsafe fn hint_unreachable() -> ! { - fake_type() + fake_type() //~ ERROR evaluation of constant value failed } trait Const { diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.stderr b/src/test/ui/consts/uninhabited-const-issue-61744.stderr index fc908b2b2225f..024f9782d4a67 100644 --- a/src/test/ui/consts/uninhabited-const-issue-61744.stderr +++ b/src/test/ui/consts/uninhabited-const-issue-61744.stderr @@ -1,11 +1,9 @@ error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited-const-issue-61744.rs:4:5 + --> $DIR/uninhabited-const-issue-61744.rs:8:5 | LL | hint_unreachable() - | ^^^^^^^^^^^^^^^^^^ + | ------------------ | | - | reached the configured maximum number of stack frames - | inside `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:4:5 | inside `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:4:5 | inside `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:4:5 | inside `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:4:5 @@ -72,8 +70,9 @@ LL | hint_unreachable() | inside `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:4:5 ... LL | fake_type() - | ----------- + | ^^^^^^^^^^^ | | + | reached the configured maximum number of stack frames | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5 | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5 | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5