Skip to content

Commit 16e2096

Browse files
authored
Rollup merge of #110660 - compiler-errors:placeholders-pretty, r=wesleywiser,BoxyUwU
Print ty placeholders pretty Makes anon placeholders print like `!0` instead of `Placeholder { ... }`. ``` rustc_trait_selection::solve::compute_well_formed_goal goal=Goal{ predicate: !0, param_env: ParamEnv{ caller_bounds: [ Binder(TraitPredicate(<!0 as std::marker::Copy>, polarity: Positive), []), Binder(TraitPredicate(<!0 as std::clone::Clone>, polarity: Positive), []), Binder(TraitPredicate(<!0 as std::marker::Sized>, polarity: Positive), []), ], reveal: UserFacing, constness: NotConst, } } ``` cc `@BoxyUwU` who might care about this formatting decision
2 parents c8a3239 + 1d7a247 commit 16e2096

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ pub trait PrettyPrinter<'tcx>:
738738
}
739739
}
740740
ty::Placeholder(placeholder) => match placeholder.bound.kind {
741-
ty::BoundTyKind::Anon => p!(write("Placeholder({:?})", placeholder)),
741+
ty::BoundTyKind::Anon => {
742+
self.pretty_print_placeholder_var(placeholder.universe, placeholder.bound.var)?
743+
}
742744
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
743745
},
744746
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
@@ -1172,6 +1174,18 @@ pub trait PrettyPrinter<'tcx>:
11721174
}
11731175
}
11741176

1177+
fn pretty_print_placeholder_var(
1178+
&mut self,
1179+
ui: ty::UniverseIndex,
1180+
var: ty::BoundVar,
1181+
) -> Result<(), Self::Error> {
1182+
if ui == ty::UniverseIndex::ROOT {
1183+
write!(self, "!{}", var.index())
1184+
} else {
1185+
write!(self, "!{}_{}", ui.index(), var.index())
1186+
}
1187+
}
1188+
11751189
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
11761190
None
11771191
}

compiler/rustc_type_ir/src/sty.rs

+10
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ pub enum TyKind<I: Interner> {
203203
/// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
204204
/// back to inference variables in a new inference context when inside of the query.
205205
///
206+
/// It is conventional to render anonymous bound types like `^N` or `^D_N`,
207+
/// where `N` is the bound variable's anonymous index into the binder, and
208+
/// `D` is the debruijn index, or totally omitted if the debruijn index is zero.
209+
///
206210
/// See the `rustc-dev-guide` for more details about
207211
/// [higher-ranked trait bounds][1] and [canonical queries][2].
208212
///
@@ -212,6 +216,12 @@ pub enum TyKind<I: Interner> {
212216

213217
/// A placeholder type, used during higher ranked subtyping to instantiate
214218
/// bound variables.
219+
///
220+
/// It is conventional to render anonymous placeholer types like `!N` or `!U_N`,
221+
/// where `N` is the placeholder variable's anonymous index (which corresponds
222+
/// to the bound variable's index from the binder from which it was instantiated),
223+
/// and `U` is the universe index in which it is instantiated, or totally omitted
224+
/// if the universe index is zero.
215225
Placeholder(I::PlaceholderType),
216226

217227
/// A type variable used during type checking.

0 commit comments

Comments
 (0)