better TyKind::Debug
This commit is contained in:
parent
917b0b6c70
commit
976adf3d6d
9 changed files with 176 additions and 78 deletions
|
@ -115,6 +115,16 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||||
type FreeRegion = ty::FreeRegion;
|
type FreeRegion = ty::FreeRegion;
|
||||||
type RegionVid = ty::RegionVid;
|
type RegionVid = ty::RegionVid;
|
||||||
type PlaceholderRegion = ty::PlaceholderRegion;
|
type PlaceholderRegion = ty::PlaceholderRegion;
|
||||||
|
|
||||||
|
fn ty_and_mut_to_parts(
|
||||||
|
TypeAndMut { ty, mutbl }: TypeAndMut<'tcx>,
|
||||||
|
) -> (Self::Ty, Self::Mutability) {
|
||||||
|
(ty, mutbl)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mutability_is_mut(mutbl: Self::Mutability) -> bool {
|
||||||
|
mutbl.is_mut()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
|
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
|
||||||
|
|
|
@ -1496,7 +1496,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
||||||
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
|
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
|
||||||
/// regions/types/consts within the same universe simply have an unknown relationship to one
|
/// regions/types/consts within the same universe simply have an unknown relationship to one
|
||||||
/// another.
|
/// another.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
#[derive(HashStable, TyEncodable, TyDecodable)]
|
#[derive(HashStable, TyEncodable, TyDecodable)]
|
||||||
pub struct Placeholder<T> {
|
pub struct Placeholder<T> {
|
||||||
pub universe: UniverseIndex,
|
pub universe: UniverseIndex,
|
||||||
|
|
|
@ -685,29 +685,30 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
|
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
|
||||||
ty::Infer(infer_ty) => {
|
ty::Infer(infer_ty) => {
|
||||||
let verbose = self.should_print_verbose();
|
if self.should_print_verbose() {
|
||||||
|
p!(write("{:?}", ty.kind()));
|
||||||
|
return Ok(self);
|
||||||
|
}
|
||||||
|
|
||||||
if let ty::TyVar(ty_vid) = infer_ty {
|
if let ty::TyVar(ty_vid) = infer_ty {
|
||||||
if let Some(name) = self.ty_infer_name(ty_vid) {
|
if let Some(name) = self.ty_infer_name(ty_vid) {
|
||||||
p!(write("{}", name))
|
p!(write("{}", name))
|
||||||
} else {
|
} else {
|
||||||
if verbose {
|
p!(write("{}", infer_ty))
|
||||||
p!(write("{:?}", infer_ty))
|
|
||||||
} else {
|
|
||||||
p!(write("{}", infer_ty))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
|
p!(write("{}", infer_ty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Error(_) => p!("[type error]"),
|
ty::Error(_) => p!("[type error]"),
|
||||||
ty::Param(ref param_ty) => p!(print(param_ty)),
|
ty::Param(ref param_ty) => p!(print(param_ty)),
|
||||||
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
|
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
|
||||||
ty::BoundTyKind::Anon => debug_bound_var(&mut self, debruijn, bound_ty.var)?,
|
ty::BoundTyKind::Anon => {
|
||||||
|
rustc_type_ir::debug_bound_var(&mut self, debruijn, bound_ty.var)?
|
||||||
|
}
|
||||||
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
|
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
|
||||||
true if debruijn == ty::INNERMOST => p!(write("^{}", s)),
|
true => p!(write("{:?}", ty.kind())),
|
||||||
true => p!(write("^{}_{}", debruijn.index(), s)),
|
false => p!(write("{s}")),
|
||||||
false => p!(write("{}", s)),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ty::Adt(def, substs) => {
|
ty::Adt(def, substs) => {
|
||||||
|
@ -740,10 +741,11 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Placeholder(placeholder) => match placeholder.bound.kind {
|
ty::Placeholder(placeholder) => match placeholder.bound.kind {
|
||||||
ty::BoundTyKind::Anon => {
|
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
|
||||||
debug_placeholder_var(&mut self, placeholder.universe, placeholder.bound.var)?;
|
ty::BoundTyKind::Param(_, name) => match self.should_print_verbose() {
|
||||||
}
|
true => p!(write("{:?}", ty.kind())),
|
||||||
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
|
false => p!(write("{name}")),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
// We use verbose printing in 'NO_QUERIES' mode, to
|
// We use verbose printing in 'NO_QUERIES' mode, to
|
||||||
|
@ -1372,11 +1374,9 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ConstKind::Bound(debruijn, bound_var) => {
|
ty::ConstKind::Bound(debruijn, bound_var) => {
|
||||||
debug_bound_var(&mut self, debruijn, bound_var)?
|
rustc_type_ir::debug_bound_var(&mut self, debruijn, bound_var)?
|
||||||
}
|
}
|
||||||
ty::ConstKind::Placeholder(placeholder) => {
|
ty::ConstKind::Placeholder(placeholder) => p!(write("{placeholder:?}")),
|
||||||
debug_placeholder_var(&mut self, placeholder.universe, placeholder.bound)?;
|
|
||||||
},
|
|
||||||
// FIXME(generic_const_exprs):
|
// FIXME(generic_const_exprs):
|
||||||
// write out some legible representation of an abstract const?
|
// write out some legible representation of an abstract const?
|
||||||
ty::ConstKind::Expr(_) => p!("[const expr]"),
|
ty::ConstKind::Expr(_) => p!("[const expr]"),
|
||||||
|
@ -3065,27 +3065,3 @@ pub struct OpaqueFnEntry<'tcx> {
|
||||||
fn_trait_ref: Option<ty::PolyTraitRef<'tcx>>,
|
fn_trait_ref: Option<ty::PolyTraitRef<'tcx>>,
|
||||||
return_ty: Option<ty::Binder<'tcx, Term<'tcx>>>,
|
return_ty: Option<ty::Binder<'tcx, Term<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug_bound_var<T: std::fmt::Write>(
|
|
||||||
fmt: &mut T,
|
|
||||||
debruijn: ty::DebruijnIndex,
|
|
||||||
var: ty::BoundVar,
|
|
||||||
) -> Result<(), std::fmt::Error> {
|
|
||||||
if debruijn == ty::INNERMOST {
|
|
||||||
write!(fmt, "^{}", var.index())
|
|
||||||
} else {
|
|
||||||
write!(fmt, "^{}_{}", debruijn.index(), var.index())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn debug_placeholder_var<T: std::fmt::Write>(
|
|
||||||
fmt: &mut T,
|
|
||||||
universe: ty::UniverseIndex,
|
|
||||||
bound: ty::BoundVar,
|
|
||||||
) -> Result<(), std::fmt::Error> {
|
|
||||||
if universe == ty::UniverseIndex::ROOT {
|
|
||||||
write!(fmt, "!{}", bound.index())
|
|
||||||
} else {
|
|
||||||
write!(fmt, "!{}_{}", universe.index(), bound.index())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -88,7 +88,35 @@ impl fmt::Debug for ty::FreeRegion {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
|
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
|
let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = self;
|
||||||
|
|
||||||
|
write!(f, "{}", unsafety.prefix_str())?;
|
||||||
|
match abi {
|
||||||
|
rustc_target::spec::abi::Abi::Rust => (),
|
||||||
|
abi => write!(f, "extern \"{abi:?}\" ")?,
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "fn(")?;
|
||||||
|
let inputs = self.inputs();
|
||||||
|
match inputs.len() {
|
||||||
|
0 if *c_variadic => write!(f, "...)")?,
|
||||||
|
0 => write!(f, ")")?,
|
||||||
|
_ => {
|
||||||
|
for ty in &self.inputs()[0..(self.inputs().len() - 1)] {
|
||||||
|
write!(f, "{ty:?}, ")?;
|
||||||
|
}
|
||||||
|
write!(f, "{:?}", self.inputs().last().unwrap())?;
|
||||||
|
if *c_variadic {
|
||||||
|
write!(f, "...")?;
|
||||||
|
}
|
||||||
|
write!(f, ")")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.output().kind() {
|
||||||
|
ty::Tuple(list) if list.is_empty() => Ok(()),
|
||||||
|
_ => write!(f, " -> {:?}", self.output()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,20 +244,37 @@ impl<'tcx> fmt::Debug for ty::ConstKind<'tcx> {
|
||||||
match self {
|
match self {
|
||||||
Param(param) => write!(f, "{param:?}"),
|
Param(param) => write!(f, "{param:?}"),
|
||||||
Infer(var) => write!(f, "{var:?}"),
|
Infer(var) => write!(f, "{var:?}"),
|
||||||
Bound(debruijn, var) => ty::print::debug_bound_var(f, *debruijn, *var),
|
Bound(debruijn, var) => rustc_type_ir::debug_bound_var(f, *debruijn, *var),
|
||||||
Placeholder(placeholder) => {
|
Placeholder(placeholder) => write!(f, "{placeholder:?}"),
|
||||||
ty::print::debug_placeholder_var(f, placeholder.universe, placeholder.bound)
|
|
||||||
}
|
|
||||||
Unevaluated(uv) => {
|
Unevaluated(uv) => {
|
||||||
f.debug_tuple("Unevaluated").field(&uv.substs).field(&uv.def).finish()
|
f.debug_tuple("Unevaluated").field(&uv.substs).field(&uv.def).finish()
|
||||||
}
|
}
|
||||||
Value(valtree) => write!(f, "{valtree:?}"),
|
Value(valtree) => write!(f, "{valtree:?}"),
|
||||||
Error(_) => write!(f, "[const error]"),
|
Error(_) => write!(f, "{{const error}}"),
|
||||||
Expr(expr) => write!(f, "{expr:?}"),
|
Expr(expr) => write!(f, "{expr:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ty::BoundTy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self.kind {
|
||||||
|
ty::BoundTyKind::Anon => write!(f, "{:?}", self.var),
|
||||||
|
ty::BoundTyKind::Param(_, sym) => write!(f, "{sym:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: fmt::Debug> fmt::Debug for ty::Placeholder<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
if self.universe == ty::UniverseIndex::ROOT {
|
||||||
|
write!(f, "!{:?}", self.bound)
|
||||||
|
} else {
|
||||||
|
write!(f, "!{}_{:?}", self.universe.index(), self.bound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Atomic structs
|
// Atomic structs
|
||||||
//
|
//
|
||||||
|
@ -294,6 +339,7 @@ TrivialTypeTraversalAndLiftImpls! {
|
||||||
crate::ty::AliasRelationDirection,
|
crate::ty::AliasRelationDirection,
|
||||||
crate::ty::Placeholder<crate::ty::BoundRegion>,
|
crate::ty::Placeholder<crate::ty::BoundRegion>,
|
||||||
crate::ty::Placeholder<crate::ty::BoundTy>,
|
crate::ty::Placeholder<crate::ty::BoundTy>,
|
||||||
|
crate::ty::Placeholder<ty::BoundVar>,
|
||||||
crate::ty::ClosureKind,
|
crate::ty::ClosureKind,
|
||||||
crate::ty::FreeRegion,
|
crate::ty::FreeRegion,
|
||||||
crate::ty::InferTy,
|
crate::ty::InferTy,
|
||||||
|
@ -310,7 +356,6 @@ TrivialTypeTraversalAndLiftImpls! {
|
||||||
interpret::Scalar,
|
interpret::Scalar,
|
||||||
rustc_target::abi::Size,
|
rustc_target::abi::Size,
|
||||||
ty::BoundVar,
|
ty::BoundVar,
|
||||||
ty::Placeholder<ty::BoundVar>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TrivialTypeTraversalAndLiftImpls! {
|
TrivialTypeTraversalAndLiftImpls! {
|
||||||
|
|
|
@ -1511,10 +1511,11 @@ impl Atom for RegionVid {
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
#[derive(HashStable)]
|
#[derive(HashStable)]
|
||||||
|
#[debug_format = "{}"]
|
||||||
pub struct BoundVar {}
|
pub struct BoundVar {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||||
#[derive(HashStable)]
|
#[derive(HashStable)]
|
||||||
pub struct BoundTy {
|
pub struct BoundTy {
|
||||||
pub var: BoundVar,
|
pub var: BoundVar,
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub trait Interner: Sized {
|
||||||
type PolyFnSig: Clone + Debug + Hash + Ord;
|
type PolyFnSig: Clone + Debug + Hash + Ord;
|
||||||
type ListBinderExistentialPredicate: Clone + Debug + Hash + Ord;
|
type ListBinderExistentialPredicate: Clone + Debug + Hash + Ord;
|
||||||
type BinderListTy: Clone + Debug + Hash + Ord;
|
type BinderListTy: Clone + Debug + Hash + Ord;
|
||||||
type ListTy: Clone + Debug + Hash + Ord;
|
type ListTy: Clone + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>;
|
||||||
type AliasTy: Clone + Debug + Hash + Ord;
|
type AliasTy: Clone + Debug + Hash + Ord;
|
||||||
type ParamTy: Clone + Debug + Hash + Ord;
|
type ParamTy: Clone + Debug + Hash + Ord;
|
||||||
type BoundTy: Clone + Debug + Hash + Ord;
|
type BoundTy: Clone + Debug + Hash + Ord;
|
||||||
|
@ -67,6 +67,9 @@ pub trait Interner: Sized {
|
||||||
type FreeRegion: Clone + Debug + Hash + Ord;
|
type FreeRegion: Clone + Debug + Hash + Ord;
|
||||||
type RegionVid: Clone + Debug + Hash + Ord;
|
type RegionVid: Clone + Debug + Hash + Ord;
|
||||||
type PlaceholderRegion: Clone + Debug + Hash + Ord;
|
type PlaceholderRegion: Clone + Debug + Hash + Ord;
|
||||||
|
|
||||||
|
fn ty_and_mut_to_parts(ty_and_mut: Self::TypeAndMut) -> (Self::Ty, Self::Mutability);
|
||||||
|
fn mutability_is_mut(mutbl: Self::Mutability) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
|
/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
|
||||||
|
@ -390,7 +393,19 @@ impl DebruijnIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
pub fn debug_bound_var<T: std::fmt::Write>(
|
||||||
|
fmt: &mut T,
|
||||||
|
debruijn: DebruijnIndex,
|
||||||
|
var: impl std::fmt::Debug,
|
||||||
|
) -> Result<(), std::fmt::Error> {
|
||||||
|
if debruijn == INNERMOST {
|
||||||
|
write!(fmt, "^{:?}", var)
|
||||||
|
} else {
|
||||||
|
write!(fmt, "^{}_{:?}", debruijn.index(), var)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(Encodable, Decodable, HashStable_Generic)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum IntTy {
|
pub enum IntTy {
|
||||||
Isize,
|
Isize,
|
||||||
|
@ -448,7 +463,7 @@ impl IntTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
||||||
#[derive(Encodable, Decodable, HashStable_Generic)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum UintTy {
|
pub enum UintTy {
|
||||||
Usize,
|
Usize,
|
||||||
|
@ -506,7 +521,7 @@ impl UintTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(Encodable, Decodable, HashStable_Generic)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum FloatTy {
|
pub enum FloatTy {
|
||||||
F32,
|
F32,
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
use crate::fold::{FallibleTypeFolder, TypeFoldable};
|
use crate::fold::{FallibleTypeFolder, TypeFoldable};
|
||||||
use crate::visit::{TypeVisitable, TypeVisitor};
|
use crate::visit::{TypeVisitable, TypeVisitor};
|
||||||
use crate::Interner;
|
use crate::{FloatTy, IntTy, Interner, UintTy};
|
||||||
use rustc_data_structures::functor::IdFunctor;
|
use rustc_data_structures::functor::IdFunctor;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_index::{Idx, IndexVec};
|
use rustc_index::{Idx, IndexVec};
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -163,3 +164,21 @@ impl<I: Interner, T: TypeVisitable<I>, Ix: Idx> TypeVisitable<I> for IndexVec<Ix
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for IntTy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.name_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for UintTy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.name_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for FloatTy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.name_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -294,7 +294,7 @@ impl<I: Interner> Clone for TyKind<I> {
|
||||||
Str => Str,
|
Str => Str,
|
||||||
Array(t, c) => Array(t.clone(), c.clone()),
|
Array(t, c) => Array(t.clone(), c.clone()),
|
||||||
Slice(t) => Slice(t.clone()),
|
Slice(t) => Slice(t.clone()),
|
||||||
RawPtr(t) => RawPtr(t.clone()),
|
RawPtr(p) => RawPtr(p.clone()),
|
||||||
Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()),
|
Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()),
|
||||||
FnDef(d, s) => FnDef(d.clone(), s.clone()),
|
FnDef(d, s) => FnDef(d.clone(), s.clone()),
|
||||||
FnPtr(s) => FnPtr(s.clone()),
|
FnPtr(s) => FnPtr(s.clone()),
|
||||||
|
@ -499,33 +499,65 @@ impl<I: Interner> hash::Hash for TyKind<I> {
|
||||||
impl<I: Interner> fmt::Debug for TyKind<I> {
|
impl<I: Interner> fmt::Debug for TyKind<I> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Bool => f.write_str("Bool"),
|
Bool => write!(f, "bool"),
|
||||||
Char => f.write_str("Char"),
|
Char => write!(f, "char"),
|
||||||
Int(i) => f.debug_tuple_field1_finish("Int", i),
|
Int(i) => write!(f, "{i:?}"),
|
||||||
Uint(u) => f.debug_tuple_field1_finish("Uint", u),
|
Uint(u) => write!(f, "{u:?}"),
|
||||||
Float(float) => f.debug_tuple_field1_finish("Float", float),
|
Float(float) => write!(f, "{float:?}"),
|
||||||
Adt(d, s) => f.debug_tuple_field2_finish("Adt", d, s),
|
Adt(d, s) => f.debug_tuple_field2_finish("Adt", d, s),
|
||||||
Foreign(d) => f.debug_tuple_field1_finish("Foreign", d),
|
Foreign(d) => f.debug_tuple_field1_finish("Foreign", d),
|
||||||
Str => f.write_str("Str"),
|
Str => write!(f, "str"),
|
||||||
Array(t, c) => f.debug_tuple_field2_finish("Array", t, c),
|
Array(t, c) => write!(f, "[{t:?}; {c:?}]"),
|
||||||
Slice(t) => f.debug_tuple_field1_finish("Slice", t),
|
Slice(t) => write!(f, "[{t:?}]"),
|
||||||
RawPtr(t) => f.debug_tuple_field1_finish("RawPtr", t),
|
RawPtr(p) => {
|
||||||
Ref(r, t, m) => f.debug_tuple_field3_finish("Ref", r, t, m),
|
let (ty, mutbl) = I::ty_and_mut_to_parts(p.clone());
|
||||||
|
match I::mutability_is_mut(mutbl) {
|
||||||
|
true => write!(f, "*mut "),
|
||||||
|
false => write!(f, "*const "),
|
||||||
|
}?;
|
||||||
|
write!(f, "{ty:?}")
|
||||||
|
}
|
||||||
|
Ref(r, t, m) => match I::mutability_is_mut(m.clone()) {
|
||||||
|
true => write!(f, "&{r:?} mut {t:?}"),
|
||||||
|
false => write!(f, "&{r:?} {t:?}"),
|
||||||
|
},
|
||||||
FnDef(d, s) => f.debug_tuple_field2_finish("FnDef", d, s),
|
FnDef(d, s) => f.debug_tuple_field2_finish("FnDef", d, s),
|
||||||
FnPtr(s) => f.debug_tuple_field1_finish("FnPtr", s),
|
FnPtr(s) => write!(f, "{s:?}"),
|
||||||
Dynamic(p, r, repr) => f.debug_tuple_field3_finish("Dynamic", p, r, repr),
|
Dynamic(p, r, repr) => match repr {
|
||||||
|
DynKind::Dyn => write!(f, "dyn {p:?} + {r:?}"),
|
||||||
|
DynKind::DynStar => write!(f, "dyn* {p:?} + {r:?}"),
|
||||||
|
},
|
||||||
Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, s),
|
Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, s),
|
||||||
Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, s, m),
|
Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, s, m),
|
||||||
GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g),
|
GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g),
|
||||||
GeneratorWitnessMIR(d, s) => f.debug_tuple_field2_finish("GeneratorWitnessMIR", d, s),
|
GeneratorWitnessMIR(d, s) => f.debug_tuple_field2_finish("GeneratorWitnessMIR", d, s),
|
||||||
Never => f.write_str("Never"),
|
Never => write!(f, "!"),
|
||||||
Tuple(t) => f.debug_tuple_field1_finish("Tuple", t),
|
Tuple(t) => {
|
||||||
|
let mut iter = t.clone().into_iter();
|
||||||
|
|
||||||
|
write!(f, "(")?;
|
||||||
|
|
||||||
|
match iter.next() {
|
||||||
|
None => return write!(f, ")"),
|
||||||
|
Some(ty) => write!(f, "{ty:?}")?,
|
||||||
|
};
|
||||||
|
|
||||||
|
match iter.next() {
|
||||||
|
None => return write!(f, ",)"),
|
||||||
|
Some(ty) => write!(f, "{ty:?})")?,
|
||||||
|
}
|
||||||
|
|
||||||
|
for ty in iter {
|
||||||
|
write!(f, ", {ty:?}")?;
|
||||||
|
}
|
||||||
|
write!(f, ")")
|
||||||
|
}
|
||||||
Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a),
|
Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a),
|
||||||
Param(p) => f.debug_tuple_field1_finish("Param", p),
|
Param(p) => write!(f, "{p:?}"),
|
||||||
Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b),
|
Bound(d, b) => crate::debug_bound_var(f, *d, b),
|
||||||
Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p),
|
Placeholder(p) => write!(f, "{p:?}"),
|
||||||
Infer(t) => f.debug_tuple_field1_finish("Infer", t),
|
Infer(t) => write!(f, "{t:?}"),
|
||||||
TyKind::Error(e) => f.debug_tuple_field1_finish("Error", e),
|
TyKind::Error(_) => write!(f, "{{type error}}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
DefId(0:3 ~ thir_flat[7b97]::main):
|
DefId(0:3 ~ thir_flat[7b97]::main):
|
||||||
Thir {
|
Thir {
|
||||||
body_type: Fn(
|
body_type: Fn(
|
||||||
([]; c_variadic: false)->(),
|
fn(),
|
||||||
),
|
),
|
||||||
arms: [],
|
arms: [],
|
||||||
blocks: [
|
blocks: [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue