1
Fork 0

properly pretty-print inherent projections

This commit is contained in:
León Orell Valerian Liehr 2023-05-12 01:36:37 +02:00
parent c2ccc855e7
commit 778abc7a00
No known key found for this signature in database
GPG key ID: D17A07215F68E713
4 changed files with 28 additions and 4 deletions

View file

@ -1164,6 +1164,22 @@ pub trait PrettyPrinter<'tcx>:
traits.entry(trait_ref).or_default().extend(proj_ty);
}
fn pretty_print_inherent_projection(
self,
alias_ty: &ty::AliasTy<'tcx>,
) -> Result<Self::Path, Self::Error> {
let def_key = self.tcx().def_key(alias_ty.def_id);
self.path_generic_args(
|cx| {
cx.path_append(
|cx| cx.path_qualified(alias_ty.self_ty(), None),
&def_key.disambiguated_data,
)
},
&alias_ty.substs[1..],
)
}
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
None
}
@ -2821,7 +2837,11 @@ define_print_and_forward_display! {
}
ty::AliasTy<'tcx> {
p!(print_def_path(self.def_id, self.substs));
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
p!(pretty_print_inherent_projection(self))
} else {
p!(print_def_path(self.def_id, self.substs));
}
}
ty::ClosureKind {