1
Fork 0

Remove DebugWithInfcx

This commit is contained in:
Michael Goulet 2024-06-06 10:08:55 -04:00
parent ebcb862bbb
commit 0fc18e3a17
17 changed files with 105 additions and 477 deletions

View file

@ -1,5 +1,5 @@
use super::flags::FlagComputation;
use super::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, TyCtxt, TypeFlags, WithInfcx};
use super::{DebruijnIndex, TypeFlags};
use crate::arena::Arena;
use rustc_data_structures::aligned::{align_of, Aligned};
use rustc_serialize::{Encodable, Encoder};
@ -162,14 +162,6 @@ impl<H, T: fmt::Debug> fmt::Debug for RawList<H, T> {
(**self).fmt(f)
}
}
impl<'tcx, H, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for RawList<H, T> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
fmt::Debug::fmt(&this.map(|this| this.as_slice()), f)
}
}
impl<H, S: Encoder, T: Encodable<S>> Encodable<S> for RawList<H, T> {
#[inline]

View file

@ -61,7 +61,6 @@ use rustc_span::{ExpnId, ExpnKind, Span};
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
pub use rustc_target::abi::{ReprFlags, ReprOptions};
pub use rustc_type_ir::relate::VarianceDiagInfo;
pub use rustc_type_ir::{DebugWithInfcx, InferCtxtLike, WithInfcx};
use tracing::{debug, instrument};
pub use vtable::*;

View file

@ -13,7 +13,7 @@ use rustc_ast_ir::visit::VisitorResult;
use rustc_hir::def::Namespace;
use rustc_span::source_map::Spanned;
use rustc_target::abi::TyAndLayout;
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx};
use rustc_type_ir::ConstKind;
use std::fmt::{self, Debug};
@ -83,14 +83,6 @@ impl fmt::Debug for ty::LateParamRegion {
}
}
impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
this.data.fmt(f)
}
}
impl<'tcx> fmt::Debug for Ty<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
with_no_trimmed_paths!(fmt::Debug::fmt(self.kind(), f))
@ -121,70 +113,33 @@ impl<'tcx> fmt::Debug for ty::Clause<'tcx> {
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Pattern<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
match &**this.data {
ty::PatternKind::Range { start, end, include_end } => f
.debug_struct("Pattern::Range")
.field("start", start)
.field("end", end)
.field("include_end", include_end)
.finish(),
}
}
}
impl<'tcx> fmt::Debug for ty::consts::Expr<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
WithInfcx::with_no_infcx(self).fmt(f)
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
match this.data.kind {
match self.kind {
ty::ExprKind::Binop(op) => {
let (lhs_ty, rhs_ty, lhs, rhs) = this.data.binop_args();
write!(
f,
"({op:?}: ({:?}: {:?}), ({:?}: {:?}))",
&this.wrap(lhs),
&this.wrap(lhs_ty),
&this.wrap(rhs),
&this.wrap(rhs_ty),
)
let (lhs_ty, rhs_ty, lhs, rhs) = self.binop_args();
write!(f, "({op:?}: ({:?}: {:?}), ({:?}: {:?}))", lhs, lhs_ty, rhs, rhs_ty,)
}
ty::ExprKind::UnOp(op) => {
let (rhs_ty, rhs) = this.data.unop_args();
write!(f, "({op:?}: ({:?}: {:?}))", &this.wrap(rhs), &this.wrap(rhs_ty))
let (rhs_ty, rhs) = self.unop_args();
write!(f, "({op:?}: ({:?}: {:?}))", rhs, rhs_ty)
}
ty::ExprKind::FunctionCall => {
let (func_ty, func, args) = this.data.call_args();
let (func_ty, func, args) = self.call_args();
let args = args.collect::<Vec<_>>();
write!(f, "({:?}: {:?})(", &this.wrap(func), &this.wrap(func_ty))?;
write!(f, "({:?}: {:?})(", func, func_ty)?;
for arg in args.iter().rev().skip(1).rev() {
write!(f, "{:?}, ", &this.wrap(arg))?;
write!(f, "{:?}, ", arg)?;
}
if let Some(arg) = args.last() {
write!(f, "{:?}", &this.wrap(arg))?;
write!(f, "{:?}", arg)?;
}
write!(f, ")")
}
ty::ExprKind::Cast(kind) => {
let (value_ty, value, to_ty) = this.data.cast_args();
write!(
f,
"({kind:?}: ({:?}: {:?}), {:?})",
&this.wrap(value),
&this.wrap(value_ty),
&this.wrap(to_ty)
)
let (value_ty, value, to_ty) = self.cast_args();
write!(f, "({kind:?}: ({:?}: {:?}), {:?})", value, value_ty, to_ty)
}
}
}
@ -192,20 +147,12 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
impl<'tcx> fmt::Debug for ty::Const<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
WithInfcx::with_no_infcx(self).fmt(f)
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
// If this is a value, we spend some effort to make it look nice.
if let ConstKind::Value(_, _) = this.data.kind() {
if let ConstKind::Value(_, _) = self.kind() {
return ty::tls::with(move |tcx| {
// Somehow trying to lift the valtree results in lifetime errors, so we lift the
// entire constant.
let lifted = tcx.lift(*this.data).unwrap();
let lifted = tcx.lift(*self).unwrap();
let ConstKind::Value(ty, valtree) = lifted.kind() else {
bug!("we checked that this is a valtree")
};
@ -215,7 +162,7 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
});
}
// Fall back to something verbose.
write!(f, "{kind:?}", kind = &this.map(|data| data.kind()))
write!(f, "{:?}", self.kind())
}
}
@ -247,32 +194,12 @@ impl<'tcx> fmt::Debug for GenericArg<'tcx> {
}
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for GenericArg<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
match this.data.unpack() {
GenericArgKind::Lifetime(lt) => write!(f, "{:?}", &this.wrap(lt)),
GenericArgKind::Const(ct) => write!(f, "{:?}", &this.wrap(ct)),
GenericArgKind::Type(ty) => write!(f, "{:?}", &this.wrap(ty)),
}
}
}
impl<'tcx> fmt::Debug for Region<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.kind())
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
write!(f, "{:?}", &this.map(|data| data.kind()))
}
}
///////////////////////////////////////////////////////////////////////////
// Atomic structs