Skip to content

Commit fe30d5f

Browse files
committed
rustc_codegen_utils: print all nominal types as paths, in symbol names.
1 parent 82ee912 commit fe30d5f

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
@@ -423,7 +423,18 @@ impl Printer for SymbolPath {
423423
self: PrintCx<'_, '_, 'tcx, Self>,
424424
ty: Ty<'tcx>,
425425
) -> Result<Self::Type, Self::Error> {
426-
self.pretty_print_type(ty)
426+
match ty.sty {
427+
// Print all nominal types as paths (unlike `pretty_print_type`).
428+
ty::FnDef(def_id, substs) |
429+
ty::Opaque(def_id, substs) |
430+
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
431+
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
432+
ty::Closure(def_id, ty::ClosureSubsts { substs }) |
433+
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
434+
self.print_def_path(def_id, Some(substs), iter::empty())
435+
}
436+
_ => self.pretty_print_type(ty),
437+
}
427438
}
428439

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

444470
fn path_append_impl<'gcx, 'tcx>(

0 commit comments

Comments
 (0)