Skip to content

Commit 6d67d68

Browse files
committed
rustc_codegen_utils: print all nominal types as paths, in symbol names.
1 parent 5211e37 commit 6d67d68

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,18 @@ impl Printer for SymbolPath {
422422
self: PrintCx<'_, '_, 'tcx, Self>,
423423
ty: Ty<'tcx>,
424424
) -> Result<Self::Type, Self::Error> {
425-
self.pretty_print_type(ty)
425+
match ty.sty {
426+
// Print all nominal types as paths (unlike `pretty_print_type`).
427+
ty::FnDef(def_id, substs) |
428+
ty::Opaque(def_id, substs) |
429+
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
430+
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
431+
ty::Closure(def_id, ty::ClosureSubsts { substs }) |
432+
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
433+
self.print_def_path(def_id, Some(substs), iter::empty())
434+
}
435+
_ => self.pretty_print_type(ty),
436+
}
426437
}
427438

428439
fn path_crate(
@@ -437,7 +448,22 @@ impl Printer for SymbolPath {
437448
self_ty: Ty<'tcx>,
438449
trait_ref: Option<ty::TraitRef<'tcx>>,
439450
) -> Result<Self::Path, Self::Error> {
440-
self.pretty_path_qualified(self_ty, trait_ref)
451+
// Similar to `pretty_path_qualified`, but for the other
452+
// types that are printed as paths (see `print_type` above).
453+
match self_ty.sty {
454+
ty::FnDef(..) |
455+
ty::Opaque(..) |
456+
ty::Projection(_) |
457+
ty::UnnormalizedProjection(_) |
458+
ty::Closure(..) |
459+
ty::Generator(..)
460+
if trait_ref.is_none() =>
461+
{
462+
self.print_type(self_ty)
463+
}
464+
465+
_ => self.pretty_path_qualified(self_ty, trait_ref)
466+
}
441467
}
442468

443469
fn path_append_impl<'gcx, 'tcx>(

0 commit comments

Comments
 (0)