Print ty placeholders pretty

This commit is contained in:
Michael Goulet 2023-04-20 21:02:30 +00:00
parent fa4cc63a6b
commit 1d7a2472bf
2 changed files with 25 additions and 1 deletions

View File

@ -738,7 +738,9 @@ pub trait PrettyPrinter<'tcx>:
}
}
ty::Placeholder(placeholder) => match placeholder.bound.kind {
ty::BoundTyKind::Anon => p!(write("Placeholder({:?})", placeholder)),
ty::BoundTyKind::Anon => {
self.pretty_print_placeholder_var(placeholder.universe, placeholder.bound.var)?
}
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
},
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
@ -1172,6 +1174,18 @@ pub trait PrettyPrinter<'tcx>:
}
}
fn pretty_print_placeholder_var(
&mut self,
ui: ty::UniverseIndex,
var: ty::BoundVar,
) -> Result<(), Self::Error> {
if ui == ty::UniverseIndex::ROOT {
write!(self, "!{}", var.index())
} else {
write!(self, "!{}_{}", ui.index(), var.index())
}
}
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
None
}

View File

@ -203,6 +203,10 @@ pub enum TyKind<I: Interner> {
/// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
/// back to inference variables in a new inference context when inside of the query.
///
/// It is conventional to render anonymous bound types like `^N` or `^D_N`,
/// where `N` is the bound variable's anonymous index into the binder, and
/// `D` is the debruijn index, or totally omitted if the debruijn index is zero.
///
/// See the `rustc-dev-guide` for more details about
/// [higher-ranked trait bounds][1] and [canonical queries][2].
///
@ -212,6 +216,12 @@ pub enum TyKind<I: Interner> {
/// A placeholder type, used during higher ranked subtyping to instantiate
/// bound variables.
///
/// It is conventional to render anonymous placeholer types like `!N` or `!U_N`,
/// where `N` is the placeholder variable's anonymous index (which corresponds
/// to the bound variable's index from the binder from which it was instantiated),
/// and `U` is the universe index in which it is instantiated, or totally omitted
/// if the universe index is zero.
Placeholder(I::PlaceholderType),
/// A type variable used during type checking.