Skip to content

Commit

Permalink
special case TyAndLayout debug impl
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Jan 30, 2023
1 parent 6f011f1 commit 9bdf7ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
23 changes: 21 additions & 2 deletions compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,18 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {

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

impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for ArgAbi<'a, Ty> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ArgAbi").field("layout", &self.layout).field("mode", &self.mode).finish()
}
}

impl<'a, Ty> ArgAbi<'a, Ty> {
pub fn new(
cx: &impl HasDataLayout,
Expand Down Expand Up @@ -605,7 +611,7 @@ pub enum Conv {
///
/// I will do my best to describe this structure, but these
/// comments are reverse-engineered and may be inaccurate. -NDM
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
#[derive(PartialEq, Eq, Hash, HashStable_Generic)]
pub struct FnAbi<'a, Ty> {
/// The LLVM types of each argument.
pub args: Box<[ArgAbi<'a, Ty>]>,
Expand All @@ -626,6 +632,19 @@ pub struct FnAbi<'a, Ty> {
pub can_unwind: bool,
}

impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FnAbi")
.field("args", &self.args)
.field("ret", &self.ret)
.field("c_variadic", &self.c_variadic)
.field("fixed_count", &self.fixed_count)
.field("conv", &self.conv)
.field("can_unwind", &self.can_unwind)
.finish()
}
}

/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum AdjustForForeignAbiError {
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,21 @@ impl<'a> Layout<'a> {
/// to that obtained from `layout_of(ty)`, as we need to produce
/// layouts for which Rust types do not exist, such as enum variants
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
pub struct TyAndLayout<'a, Ty> {
pub ty: Ty,
pub layout: Layout<'a>,
}

impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TyAndLayout")
.field("ty", &format_args!("{}", &self.ty))
.field("layout", &self.layout)
.finish()
}
}

impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
type Target = &'a LayoutS<VariantIdx>;
fn deref(&self) -> &&'a LayoutS<VariantIdx> {
Expand Down

0 comments on commit 9bdf7ca

Please sign in to comment.