Skip to content

Commit

Permalink
impl Display for Conv
Browse files Browse the repository at this point in the history
  • Loading branch information
tiif committed Jan 21, 2025
1 parent b605c65 commit bbde683
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,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),
)
}

Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::str::FromStr;
use std::{fmt, iter};

Expand Down Expand Up @@ -881,6 +882,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 {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,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
);
}
Expand Down

0 comments on commit bbde683

Please sign in to comment.