about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2018-12-21 17:31:33 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2019-03-15 13:25:10 +0200
commitaec5a484812e2e6d0077a960997f1f51f18c1c8a (patch)
tree0cb68f70bb7d1b6d2ce8fd418679af95070d1eab /src
parenta15bfc6f483c552f793932f7ac7fcbb69d187681 (diff)
downloadrust-aec5a484812e2e6d0077a960997f1f51f18c1c8a.tar.gz
rust-aec5a484812e2e6d0077a960997f1f51f18c1c8a.zip
rustc: move <...>-less impl path special-case to pretty_path_qualified.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/print.rs65
-rw-r--r--src/librustc/util/ppaux.rs2
-rw-r--r--src/librustc_codegen_utils/symbol_names.rs18
-rw-r--r--src/librustdoc/clean/mod.rs4
4 files changed, 43 insertions, 46 deletions
diff --git a/src/librustc/ty/print.rs b/src/librustc/ty/print.rs
index 45762460f2d..77fed9cf1d1 100644
--- a/src/librustc/ty/print.rs
+++ b/src/librustc/ty/print.rs
@@ -173,10 +173,9 @@ pub trait Printer: Sized {
         self: &mut PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
+        ns: Namespace,
     ) -> Self::Path;
     #[must_use]
-    fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path;
-    #[must_use]
     fn path_append(
         self: &mut PrintCx<'_, '_, '_, Self>,
         path: Self::Path,
@@ -291,7 +290,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
                         parent_generics.has_self && parent_generics.parent_count == 0;
                     if let (Some(substs), true) = (substs, parent_has_own_self) {
                         let trait_ref = ty::TraitRef::new(parent_def_id, substs);
-                        self.path_qualified(trait_ref.self_ty(), Some(trait_ref))
+                        self.path_qualified(trait_ref.self_ty(), Some(trait_ref), ns)
                     } else {
                         self.print_def_path(parent_def_id, substs, ns, iter::empty())
                     }
@@ -367,35 +366,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
 
         // Otherwise, try to give a good form that would be valid language
         // syntax. Preferably using associated item notation.
-
-        if let Some(trait_ref) = impl_trait_ref {
-            // Trait impls.
-            return self.path_qualified(self_ty, Some(trait_ref));
-        }
-
-        // Inherent impls. Try to print `Foo::bar` for an inherent
-        // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
-        // anything other than a simple path.
-        match self_ty.sty {
-            ty::Adt(adt_def, substs) => {
-                self.print_def_path(adt_def.did, Some(substs), ns, iter::empty())
-            }
-
-            ty::Foreign(did) => self.print_def_path(did, None, ns, iter::empty()),
-
-            ty::Bool |
-            ty::Char |
-            ty::Int(_) |
-            ty::Uint(_) |
-            ty::Float(_) |
-            ty::Str => {
-                self.path_impl(&self_ty.to_string())
-            }
-
-            _ => {
-                self.path_qualified(self_ty, None)
-            }
-        }
+        self.path_qualified(self_ty, impl_trait_ref, ns)
     }
 }
 
@@ -587,7 +558,30 @@ impl<P: PrettyPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
         &mut self,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
+        ns: Namespace,
     ) -> P::Path {
+        if trait_ref.is_none() {
+            // Inherent impls. Try to print `Foo::bar` for an inherent
+            // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
+            // anything other than a simple path.
+            match self_ty.sty {
+                ty::Adt(adt_def, substs) => {
+                    return self.print_def_path(adt_def.did, Some(substs), ns, iter::empty());
+                }
+                ty::Foreign(did) => {
+                    return self.print_def_path(did, None, ns, iter::empty());
+                }
+
+                ty::Bool | ty::Char | ty::Str |
+                ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
+                    self_ty.print_display(self)?;
+                    return Ok(PrettyPath { empty: false });
+                }
+
+                _ => {}
+            }
+        }
+
         write!(self.printer, "<")?;
         self_ty.print_display(self)?;
         if let Some(trait_ref) = trait_ref {
@@ -781,12 +775,9 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
         self: &mut PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
+        ns: Namespace,
     ) -> Self::Path {
-        self.pretty_path_qualified(self_ty, trait_ref)
-    }
-    fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path {
-        write!(self.printer, "{}", text)?;
-        Ok(PrettyPath { empty: false })
+        self.pretty_path_qualified(self_ty, trait_ref, ns)
     }
     fn path_append(
         self: &mut PrintCx<'_, '_, '_, Self>,
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs
index 2c38c437cf6..3c34d254099 100644
--- a/src/librustc/util/ppaux.rs
+++ b/src/librustc/util/ppaux.rs
@@ -1007,7 +1007,7 @@ define_print! {
             Ok(())
         }
         debug {
-            let _ = cx.path_qualified(self.self_ty(), Some(*self))?;
+            let _ = cx.path_qualified(self.self_ty(), Some(*self), Namespace::TypeNS)?;
             Ok(())
         }
     }
diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs
index 4c7b00ae078..0ea141b6574 100644
--- a/src/librustc_codegen_utils/symbol_names.rs
+++ b/src/librustc_codegen_utils/symbol_names.rs
@@ -416,16 +416,24 @@ impl Printer for SymbolPath {
         self: &mut PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
+        ns: Namespace,
     ) -> Self::Path {
+        // HACK(eddyb) avoid `keep_within_component` for the cases
+        // that print without `<...>` around `self_ty`.
+        match self_ty.sty {
+            ty::Adt(..) | ty::Foreign(_) |
+            ty::Bool | ty::Char | ty::Str |
+            ty::Int(_) | ty::Uint(_) | ty::Float(_) if trait_ref.is_none() => {
+                return self.pretty_path_qualified(self_ty, trait_ref, ns);
+            }
+            _ => {}
+        }
+
         let kept_within_component = mem::replace(&mut self.printer.keep_within_component, true);
-        let r = self.pretty_path_qualified(self_ty, trait_ref);
+        let r = self.pretty_path_qualified(self_ty, trait_ref, ns);
         self.printer.keep_within_component = kept_within_component;
         r
     }
-    fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path {
-        self.printer.write_str(text)?;
-        Ok(PrettyPath { empty: false })
-    }
     fn path_append(
         self: &mut PrintCx<'_, '_, '_, Self>,
         _: Self::Path,
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index f629447fc64..4cc18125e04 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -4239,6 +4239,7 @@ where F: Fn(DefId) -> Def {
             self: &mut PrintCx<'_, '_, 'tcx, Self>,
             self_ty: Ty<'tcx>,
             trait_ref: Option<ty::TraitRef<'tcx>>,
+            _ns: Namespace,
         ) -> Self::Path {
             // This shouldn't ever be needed, but just in case:
             if let Some(trait_ref) = trait_ref {
@@ -4247,9 +4248,6 @@ where F: Fn(DefId) -> Def {
                 vec![format!("<{}>", self_ty)]
             }
         }
-        fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path {
-            vec![text.to_string()]
-        }
         fn path_append(
             self: &mut PrintCx<'_, '_, '_, Self>,
             mut path: Self::Path,