]> git.lizzy.rs Git - rust.git/commitdiff
rustc_codegen_utils: print all nominal types as paths, in symbol names.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 14 Jan 2019 22:41:14 +0000 (00:41 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 11:25:10 +0000 (13:25 +0200)
src/librustc_codegen_utils/symbol_names.rs

index 3c8bd0dd01b47477185d85f3b126afaeeec230e8..a17a554480eb80b313273fc3c9dae3b46fb5ca40 100644 (file)
@@ -422,7 +422,18 @@ fn print_type(
         self: PrintCx<'_, '_, 'tcx, Self>,
         ty: Ty<'tcx>,
     ) -> Result<Self::Type, Self::Error> {
-        self.pretty_print_type(ty)
+        match ty.sty {
+            // Print all nominal types as paths (unlike `pretty_print_type`).
+            ty::FnDef(def_id, substs) |
+            ty::Opaque(def_id, substs) |
+            ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
+            ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
+            ty::Closure(def_id, ty::ClosureSubsts { substs }) |
+            ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
+                self.print_def_path(def_id, Some(substs), iter::empty())
+            }
+            _ => self.pretty_print_type(ty),
+        }
     }
 
     fn path_crate(
@@ -437,7 +448,22 @@ fn path_qualified(
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
     ) -> Result<Self::Path, Self::Error> {
-        self.pretty_path_qualified(self_ty, trait_ref)
+        // Similar to `pretty_path_qualified`, but for the other
+        // types that are printed as paths (see `print_type` above).
+        match self_ty.sty {
+            ty::FnDef(..) |
+            ty::Opaque(..) |
+            ty::Projection(_) |
+            ty::UnnormalizedProjection(_) |
+            ty::Closure(..) |
+            ty::Generator(..)
+                if trait_ref.is_none() =>
+            {
+                self.print_type(self_ty)
+            }
+
+            _ => self.pretty_path_qualified(self_ty, trait_ref)
+        }
     }
 
     fn path_append_impl<'gcx, 'tcx>(