Skip to content

Commit

Permalink
Rollup merge of #101587 - BoxyUwU:term_debug, r=compiler-errors
Browse files Browse the repository at this point in the history
Make `Debug` impl for `Term` useful

because `Term { ptr: 78942378998734298342, maker: PhantomData, }` does not excel at communicating the necessary information
  • Loading branch information
compiler-errors authored Sep 8, 2022
2 parents 7300e4d + ef36af2 commit e43cf3d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,25 @@ pub struct CoercePredicate<'tcx> {
}
pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>;

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Term<'tcx> {
ptr: NonZeroUsize,
marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
}

impl Debug for Term<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let data = if let Some(ty) = self.ty() {
format!("Term::Ty({:?})", ty)
} else if let Some(ct) = self.ct() {
format!("Term::Ct({:?})", ct)
} else {
unreachable!()
};
f.write_str(&data)
}
}

impl<'tcx> From<Ty<'tcx>> for Term<'tcx> {
fn from(ty: Ty<'tcx>) -> Self {
TermKind::Ty(ty).pack()
Expand Down

0 comments on commit e43cf3d

Please sign in to comment.