diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 9d22df50d4f34..b9ba2e4606a1f 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -2,6 +2,7 @@ use std::mem; use either::{Left, Right}; +use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::def::DefKind; use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo}; use rustc_middle::mir::pretty::write_allocation_bytes; @@ -305,10 +306,13 @@ pub fn eval_to_allocation_raw_provider<'tcx>( // they do not have to behave "as if" they were evaluated at runtime. CompileTimeInterpreter::new(CanAccessStatics::from(is_static), CheckAlignment::Error), ); - eval_in_interpreter(ecx, cid, is_static) + // Evaluating this MIR in the interpreter may in turn require evaluating constants to + // allocations. As the recursion depends on what the user wrote, we need to protect ourselves + // from stack overflow. + ensure_sufficient_stack(|| eval_in_interpreter(ecx, cid, is_static)) } -pub fn eval_in_interpreter<'mir, 'tcx>( +fn eval_in_interpreter<'mir, 'tcx>( mut ecx: InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, cid: GlobalId<'tcx>, is_static: bool,