Skip to content

Commit e43cf3d

Browse files
Rollup merge of #101587 - BoxyUwU:term_debug, r=compiler-errors
Make `Debug` impl for `Term` useful because `Term { ptr: 78942378998734298342, maker: PhantomData, }` does not excel at communicating the necessary information
2 parents 7300e4d + ef36af2 commit e43cf3d

File tree

1 file changed

+14
-1
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+14
-1
lines changed

compiler/rustc_middle/src/ty/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,25 @@ pub struct CoercePredicate<'tcx> {
915915
}
916916
pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>;
917917

918-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
918+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
919919
pub struct Term<'tcx> {
920920
ptr: NonZeroUsize,
921921
marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
922922
}
923923

924+
impl Debug for Term<'_> {
925+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
926+
let data = if let Some(ty) = self.ty() {
927+
format!("Term::Ty({:?})", ty)
928+
} else if let Some(ct) = self.ct() {
929+
format!("Term::Ct({:?})", ct)
930+
} else {
931+
unreachable!()
932+
};
933+
f.write_str(&data)
934+
}
935+
}
936+
924937
impl<'tcx> From<Ty<'tcx>> for Term<'tcx> {
925938
fn from(ty: Ty<'tcx>) -> Self {
926939
TermKind::Ty(ty).pack()

0 commit comments

Comments
 (0)