impl Display for Conv

This commit is contained in:
tiif 2025-01-21 08:08:58 +00:00
parent 0998d4095b
commit 701b1948ab
3 changed files with 35 additions and 4 deletions

View file

@ -353,8 +353,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if caller_fn_abi.conv != callee_fn_abi.conv {
throw_ub_custom!(
fluent::const_eval_incompatible_calling_conventions,
callee_conv = format!("{:?}", callee_fn_abi.conv),
caller_conv = format!("{:?}", caller_fn_abi.conv),
callee_conv = format!("{}", callee_fn_abi.conv),
caller_conv = format!("{}", caller_fn_abi.conv),
)
}

View file

@ -1,3 +1,4 @@
use std::fmt::Display;
use std::str::FromStr;
use std::{fmt, iter};
@ -897,6 +898,37 @@ impl FromStr for Conv {
}
}
impl Display for Conv {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Conv::C => "C",
Conv::Rust => "Rust",
Conv::Cold => "Cold",
Conv::PreserveMost => "PreserveMost",
Conv::PreserveAll => "PreserveAll",
Conv::ArmAapcs => "ArmAapcs",
Conv::CCmseNonSecureCall => "CCmseNonSecureCall",
Conv::CCmseNonSecureEntry => "CCmseNonSecureEntry",
Conv::Msp430Intr => "Msp430Intr",
Conv::PtxKernel => "PtxKernel",
Conv::GpuKernel => "GpuKernel",
Conv::X86Fastcall => "X86Fastcall",
Conv::X86Intr => "X86Intr",
Conv::X86Stdcall => "X86Stdcall",
Conv::X86ThisCall => "X86ThisCall",
Conv::X86VectorCall => "X86VectorCall",
Conv::X86_64SysV => "X86_64SysV",
Conv::X86_64Win64 => "X86_64Win64",
Conv::AvrInterrupt => "AvrInterrupt",
Conv::AvrNonBlockingInterrupt => "AvrNonBlockingInterrupt",
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => "RiscvInterrupt(machine)",
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => {
"RiscvInterrupt(supervisor)"
}
})
}
}
// Some types are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(target_pointer_width = "64")]
mod size_asserts {

View file

@ -932,8 +932,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
if fn_abi.conv != exp_abi {
throw_ub_format!(
"calling a function with ABI {:?} using caller ABI {:?}",
exp_abi,
"calling a function with ABI {exp_abi} using caller ABI {}",
fn_abi.conv
);
}