Skip to content

Commit 9bdf7ca

Browse files
committed
special case TyAndLayout debug impl
1 parent 6f011f1 commit 9bdf7ca

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,18 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
458458

459459
/// Information about how to pass an argument to,
460460
/// or return a value from, a function, under some ABI.
461-
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
461+
#[derive(PartialEq, Eq, Hash, HashStable_Generic)]
462462
pub struct ArgAbi<'a, Ty> {
463463
pub layout: TyAndLayout<'a, Ty>,
464464
pub mode: PassMode,
465465
}
466466

467+
impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for ArgAbi<'a, Ty> {
468+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
469+
f.debug_struct("ArgAbi").field("layout", &self.layout).field("mode", &self.mode).finish()
470+
}
471+
}
472+
467473
impl<'a, Ty> ArgAbi<'a, Ty> {
468474
pub fn new(
469475
cx: &impl HasDataLayout,
@@ -605,7 +611,7 @@ pub enum Conv {
605611
///
606612
/// I will do my best to describe this structure, but these
607613
/// comments are reverse-engineered and may be inaccurate. -NDM
608-
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
614+
#[derive(PartialEq, Eq, Hash, HashStable_Generic)]
609615
pub struct FnAbi<'a, Ty> {
610616
/// The LLVM types of each argument.
611617
pub args: Box<[ArgAbi<'a, Ty>]>,
@@ -626,6 +632,19 @@ pub struct FnAbi<'a, Ty> {
626632
pub can_unwind: bool,
627633
}
628634

635+
impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
636+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
637+
f.debug_struct("FnAbi")
638+
.field("args", &self.args)
639+
.field("ret", &self.ret)
640+
.field("c_variadic", &self.c_variadic)
641+
.field("fixed_count", &self.fixed_count)
642+
.field("conv", &self.conv)
643+
.field("can_unwind", &self.can_unwind)
644+
.finish()
645+
}
646+
}
647+
629648
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
630649
#[derive(Copy, Clone, Debug, HashStable_Generic)]
631650
pub enum AdjustForForeignAbiError {

compiler/rustc_target/src/abi/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ impl<'a> Layout<'a> {
6868
/// to that obtained from `layout_of(ty)`, as we need to produce
6969
/// layouts for which Rust types do not exist, such as enum variants
7070
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
71-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
71+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
7272
pub struct TyAndLayout<'a, Ty> {
7373
pub ty: Ty,
7474
pub layout: Layout<'a>,
7575
}
7676

77+
impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> {
78+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79+
f.debug_struct("TyAndLayout")
80+
.field("ty", &format_args!("{}", &self.ty))
81+
.field("layout", &self.layout)
82+
.finish()
83+
}
84+
}
85+
7786
impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
7887
type Target = &'a LayoutS<VariantIdx>;
7988
fn deref(&self) -> &&'a LayoutS<VariantIdx> {

0 commit comments

Comments
 (0)