From bbde683a8e23afa3d8e345ec2047f0c2fad8792f Mon Sep 17 00:00:00 2001 From: tiif Date: Tue, 21 Jan 2025 08:08:58 +0000 Subject: [PATCH] impl Display for Conv --- .../rustc_const_eval/src/interpret/call.rs | 4 +-- compiler/rustc_target/src/callconv/mod.rs | 32 +++++++++++++++++++ src/tools/miri/src/helpers.rs | 3 +- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index e6a34193c9d69..653ef6f0c017b 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -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), ) } diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index 41b78d9121d6d..43546a870b1dc 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::str::FromStr; use std::{fmt, iter}; @@ -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 { diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index ca8dbdac125d0..f7ca98d1c78c1 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -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 ); }