about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-09-08 14:41:13 -0700
committerGitHub <noreply@github.com>2022-09-08 14:41:13 -0700
commite43cf3deebad3dbcbbf9bae36d9a3798d73e327d (patch)
treefda26bcbe9b43c46344e941cbe9f22767d28d75c
parent7300e4db2d8ca665b579684edb43ee64be95b546 (diff)
parentef36af2f9d44b8b57660e6b6eea227e1e99bcf2b (diff)
downloadrust-e43cf3deebad3dbcbbf9bae36d9a3798d73e327d.tar.gz
rust-e43cf3deebad3dbcbbf9bae36d9a3798d73e327d.zip
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
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 37136ff2ef5..4635a9d5575 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -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()