Handle panicking like rustc CTFE does

Instead of using `core::fmt::format` to format panic messages, which may in turn
panic too and cause recursive panics and other messy things, redirect
`panic_fmt` to `const_panic_fmt` like CTFE, which in turn goes to
`panic_display` and does the things normally. See the tests for the full
call stack.
This commit is contained in:
Nilstrieb 2024-03-24 15:39:15 +01:00
parent e265e3d518
commit 2dfe7de8b6
3 changed files with 56 additions and 40 deletions

View file

@ -2317,7 +2317,7 @@ impl Evaluator<'_> {
fn exec_fn_with_args(
&mut self,
def: FunctionId,
mut def: FunctionId,
args: &[IntervalAndTy],
generic_args: Substitution,
locals: &Locals,
@ -2335,6 +2335,9 @@ impl Evaluator<'_> {
)? {
return Ok(None);
}
if let Some(redirect_def) = self.detect_and_redirect_special_function(def)? {
def = redirect_def;
}
let arg_bytes = args.iter().map(|it| IntervalOrOwned::Borrowed(it.interval));
match self.get_mir_or_dyn_index(def, generic_args.clone(), locals, span)? {
MirOrDynIndex::Dyn(self_ty_idx) => {