Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print ty placeholders pretty #110660

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. }) => {
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_type_ir/src/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
///
Expand All @@ -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.
Expand Down