X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_mir%2Fsrc%2Fconst_eval%2Fmachine.rs;h=f8b66badb8a4c2c3f8a9c0f1d760a539d192e6ca;hb=c7d6bcc788ef6b2293d2d5166a9b0339d5d03b0a;hp=773df7d7b60c14f2f1142837d05aa0778fe16a50;hpb=d95745e5fa39680d97a52d0e07ed7842b163bacc;p=rust.git diff --git a/compiler/rustc_mir/src/const_eval/machine.rs b/compiler/rustc_mir/src/const_eval/machine.rs index 773df7d7b60..f8b66badb8a 100644 --- a/compiler/rustc_mir/src/const_eval/machine.rs +++ b/compiler/rustc_mir/src/const_eval/machine.rs @@ -201,6 +201,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, type MemoryExtra = MemoryExtra; + const PANIC_ON_ALLOC_FAIL: bool = false; // will be raised as a proper error + fn load_mir( ecx: &InterpCx<'mir, 'tcx, Self>, instance: ty::InstanceDef<'tcx>, @@ -233,12 +235,15 @@ fn find_mir_or_eval_fn( // sensitive check here. But we can at least rule out functions that are not const // at all. if !ecx.tcx.is_const_fn_raw(def.did) { - // Some functions we support even if they are non-const -- but avoid testing - // that for const fn! - ecx.hook_panic_fn(instance, args)?; - // We certainly do *not* want to actually call the fn - // though, so be sure we return here. - throw_unsup_format!("calling non-const function `{}`", instance) + // allow calling functions marked with #[default_method_body_is_const]. + if !ecx.tcx.has_attr(def.did, sym::default_method_body_is_const) { + // Some functions we support even if they are non-const -- but avoid testing + // that for const fn! + ecx.hook_panic_fn(instance, args)?; + // We certainly do *not* want to actually call the fn + // though, so be sure we return here. + throw_unsup_format!("calling non-const function `{}`", instance) + } } } // This is a const fn. Call it. @@ -306,7 +311,7 @@ fn call_intrinsic( Size::from_bytes(size as u64), align, interpret::MemoryKind::Machine(MemoryKind::Heap), - ); + )?; ecx.write_scalar(Scalar::Ptr(ptr), dest)?; } _ => { @@ -391,7 +396,7 @@ fn init_frame_extra( 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) { + if !ecx.recursion_limit.value_within_limit(ecx.stack().len() + 1) { throw_exhaust!(StackFrameLimitReached) } else { Ok(frame)