Skip to content

Commit f606e33

Browse files
committed
Use IrPrint for a few Debug impls
1 parent 532bdb3 commit f606e33

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: compiler/rustc_type_ir/src/predicate.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_NoContext, TyDecodable, TyEn
77
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
88

99
use crate::inherent::*;
10+
use crate::ir_print::IrPrint;
1011
use crate::lift::Lift;
1112
use crate::upcast::{Upcast, UpcastFrom};
1213
use crate::visit::TypeVisitableExt as _;
@@ -503,7 +504,7 @@ impl AliasTermKind {
503504
/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.
504505
/// * For an inherent projection, this would be `Ty::N<...>`.
505506
/// * For an opaque type, there is no explicit syntax.
506-
#[derive_where(Clone, Hash, PartialEq, Eq, Debug; I: Interner)]
507+
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
507508
#[derive_where(Copy; I: Interner, I::GenericArgs: Copy)]
508509
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
509510
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
@@ -533,10 +534,16 @@ pub struct AliasTerm<I: Interner> {
533534
pub def_id: I::DefId,
534535

535536
/// This field exists to prevent the creation of `AliasTerm` without using [`AliasTerm::new_from_args`].
536-
#[derive_where(skip(Debug))]
537537
_use_alias_term_new_instead: (),
538538
}
539539

540+
impl<I: Interner> fmt::Debug for AliasTerm<I> {
541+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
542+
<I as IrPrint<Self>>::print_debug(self, f)
543+
}
544+
}
545+
546+
540547
impl<I: Interner> AliasTerm<I> {
541548
pub fn new_from_args<Ir: RustIr<Interner = I>>(
542549
ir: Ir,
@@ -744,7 +751,7 @@ impl<I: Interner> ty::Binder<I, ProjectionPredicate<I>> {
744751

745752
impl<I: Interner> fmt::Debug for ProjectionPredicate<I> {
746753
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
747-
write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_term, self.term)
754+
<I as IrPrint<Self>>::print_debug(self, f)
748755
}
749756
}
750757

Diff for: compiler/rustc_type_ir/src/ty_kind.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
1414
use self::TyKind::*;
1515
pub use self::closure::*;
1616
use crate::inherent::*;
17+
use crate::ir_print::IrPrint;
1718
use crate::{self as ty, DebruijnIndex, Interner, RustIr};
1819

1920
mod closure;
@@ -329,7 +330,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
329330
/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.
330331
/// * For an inherent projection, this would be `Ty::N<...>`.
331332
/// * For an opaque type, there is no explicit syntax.
332-
#[derive_where(Clone, Hash, PartialEq, Eq, Debug; I: Interner)]
333+
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
333334
#[derive_where(Copy; I: Interner, I::GenericArgs: Copy)]
334335
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
335336
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
@@ -359,10 +360,15 @@ pub struct AliasTy<I: Interner> {
359360
pub def_id: I::DefId,
360361

361362
/// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new_from_args`].
362-
#[derive_where(skip(Debug))]
363363
pub(crate) _use_alias_ty_new_instead: (),
364364
}
365365

366+
impl<I: Interner> fmt::Debug for AliasTy<I> {
367+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
368+
<I as IrPrint<Self>>::print_debug(self, f)
369+
}
370+
}
371+
366372
impl<I: Interner> AliasTy<I> {
367373
pub fn new_from_args<Ir: RustIr<Interner = I>>(
368374
ir: Ir,

0 commit comments

Comments
 (0)