Skip to content

Commit

Permalink
Also debug
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 10, 2024
1 parent 1e5ec0a commit f368527
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,8 @@ where
Ok(())
})
}

fn print_debug(t: &T, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
with_no_trimmed_paths!(Self::print(t, fmt))
}
}
7 changes: 7 additions & 0 deletions compiler/rustc_type_ir/src/ir_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{Interner, TraitRef};

pub trait IrPrint<T> {
fn print(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
fn print_debug(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
}

macro_rules! define_display_via_print {
Expand All @@ -14,6 +15,12 @@ macro_rules! define_display_via_print {
<I as IrPrint<$ty<I>>>::print(self, fmt)
}
}

impl<I: Interner> fmt::Debug for $ty<I> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
<I as IrPrint<$ty<I>>>::print_debug(self, fmt)
}
}
)*
}
}
Expand Down
21 changes: 0 additions & 21 deletions compiler/rustc_type_ir/src/trait_ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fmt;

use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};

use crate::fold::{FallibleTypeFolder, TypeFoldable};
Expand Down Expand Up @@ -71,25 +69,6 @@ impl<I: Interner> TraitRef<I> {
}
}

impl<I: Interner> fmt::Debug for TraitRef<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let TraitRef { def_id, args, _use_trait_ref_new_instead: () } = self;
let mut args = args.into_iter().peekable();
write!(f, "{def_id:?}")?;
if args.peek().is_some() {
write!(f, "<")?;
for (i, arg) in args.enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{arg:#?}")?;
}
write!(f, ">")?;
}
Ok(())
}
}

// FIXME(compiler-errors): Make this into a `Lift_Generic` impl.
impl<I: Interner, U: Interner> Lift<U> for TraitRef<I>
where
Expand Down

0 comments on commit f368527

Please sign in to comment.