]> git.lizzy.rs Git - rust.git/commitdiff
rustc: don't pass Namespace explicitly, but rather track it in FmtPrinter.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 14 Jan 2019 21:40:53 +0000 (23:40 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 11:25:10 +0000 (13:25 +0200)
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/error_reporting/need_type_info.rs
src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
src/librustc/mir/mod.rs
src/librustc/ty/print.rs
src/librustc/util/ppaux.rs
src/librustc_codegen_utils/symbol_names.rs
src/librustc_mir/borrow_check/error_reporting.rs
src/librustdoc/clean/mod.rs

index 863e10846f4f4936bf68865a9a4baa27270396f2..ad24e15b45a5158f01999c337ee4975fa60bdf8e 100644 (file)
@@ -444,7 +444,6 @@ fn check_and_note_conflicting_crates(
         terr: &TypeError<'tcx>,
         sp: Span,
     ) {
-        use hir::def::Namespace;
         use hir::def_id::CrateNum;
         use ty::print::{PrintCx, Printer};
         use ty::subst::SubstsRef;
@@ -484,7 +483,6 @@ fn path_qualified<'tcx>(
                 self: PrintCx<'_, '_, 'tcx, Self>,
                 _self_ty: Ty<'tcx>,
                 _trait_ref: Option<ty::TraitRef<'tcx>>,
-                _ns: Namespace,
             ) -> Result<Self::Path, Self::Error> {
                 Err(NonTrivialPath)
             }
@@ -517,7 +515,6 @@ fn path_generic_args<'gcx, 'tcx>(
                 ) -> Result<Self::Path, Self::Error>,
                 _params: &[ty::GenericParamDef],
                 _substs: SubstsRef<'tcx>,
-                _ns: Namespace,
                 _projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
             ) -> Result<Self::Path, Self::Error> {
                 print_prefix(self)
@@ -530,7 +527,7 @@ fn path_generic_args<'gcx, 'tcx>(
             if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
                 let abs_path = |def_id| {
                     PrintCx::with(self.tcx, AbsolutePathPrinter, |cx| {
-                        cx.print_def_path(def_id, None, Namespace::TypeNS, iter::empty())
+                        cx.print_def_path(def_id, None, iter::empty())
                     })
                 };
 
index 26deecfdbf0fc74a9a4801076dc6c4dc6107fc1a..2fabbbeadbd9c3ef0bc73c3b8e554ebb4ef1315f 100644 (file)
@@ -1,9 +1,10 @@
+use crate::hir::def::Namespace;
 use crate::hir::{self, Local, Pat, Body, HirId};
 use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use crate::infer::InferCtxt;
 use crate::infer::type_variable::TypeVariableOrigin;
 use crate::ty::{self, Ty, Infer, TyVar};
-use ty::print::Print;
+use crate::ty::print::Print;
 use syntax::source_map::CompilerDesugaringKind;
 use syntax_pos::Span;
 use errors::DiagnosticBuilder;
@@ -79,7 +80,7 @@ pub fn extract_type_name(
         }
 
         let mut s = String::new();
-        let mut printer = ty::print::FmtPrinter::new(&mut s);
+        let mut printer = ty::print::FmtPrinter::new(&mut s, Namespace::TypeNS);
         if let Some(highlight) = highlight {
             printer.region_highlight_mode = highlight;
         }
index 65fcc69a338675c38ffc9ec65f9edde6df3912ca..39ab244dae1c572d7c04a825fae5ca018fdb0b31 100644 (file)
@@ -1,4 +1,5 @@
 use errors::DiagnosticBuilder;
+use crate::hir::def::Namespace;
 use crate::hir::def_id::DefId;
 use crate::infer::error_reporting::nice_region_error::NiceRegionError;
 use crate::infer::lexical_region_resolve::RegionResolutionError;
@@ -343,7 +344,7 @@ impl<'tcx, T> fmt::Display for Highlighted<'_, '_, 'tcx, T>
             >,
         {
             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-                let mut printer = ty::print::FmtPrinter::new(f);
+                let mut printer = ty::print::FmtPrinter::new(f, Namespace::TypeNS);
                 printer.region_highlight_mode = self.highlight;
 
                 ty::print::PrintCx::with(self.tcx, printer, |cx| {
index 70ebb7111ef7aa5deba3383fee9b4c9d38485ce9..c2cafac2d5580ca9e52d2ae0747db9e283c40d94 100644 (file)
@@ -2369,7 +2369,8 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
                 };
 
                 // When printing regions, add trailing space if necessary.
-                ty::print::PrintCx::with_tls_tcx(ty::print::FmtPrinter::new(fmt), |cx| {
+                let ns = Namespace::ValueNS;
+                ty::print::PrintCx::with_tls_tcx(ty::print::FmtPrinter::new(fmt, ns), |cx| {
                     let region = if cx.config.is_verbose || cx.config.identify_regions {
                         let mut region = region.to_string();
                         if region.len() > 0 {
index 447f02f42d24d86cb82f79d1a60679b2064a6dfc..a94ae0123d85d87905253c4faadd56f910daeaa4 100644 (file)
@@ -258,20 +258,18 @@ fn print_def_path(
         self: PrintCx<'_, '_, 'tcx, Self>,
         def_id: DefId,
         substs: Option<SubstsRef<'tcx>>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<Self::Path, Self::Error> {
-        self.default_print_def_path(def_id, substs, ns, projections)
+        self.default_print_def_path(def_id, substs, projections)
     }
     fn print_impl_path(
         self: PrintCx<'_, '_, 'tcx, Self>,
         impl_def_id: DefId,
         substs: Option<SubstsRef<'tcx>>,
-        ns: Namespace,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
     ) -> Result<Self::Path, Self::Error> {
-        self.default_print_impl_path(impl_def_id, substs, ns, self_ty, trait_ref)
+        self.default_print_impl_path(impl_def_id, substs, self_ty, trait_ref)
     }
 
     fn print_region(
@@ -292,7 +290,6 @@ fn path_qualified(
         self: PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
-        ns: Namespace,
     ) -> Result<Self::Path, Self::Error>;
 
     fn path_append_impl<'gcx, 'tcx>(
@@ -317,7 +314,6 @@ fn path_generic_args<'gcx, 'tcx>(
         ) -> Result<Self::Path, Self::Error>,
         params: &[ty::GenericParamDef],
         substs: SubstsRef<'tcx>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<Self::Path, Self::Error>;
 }
@@ -350,16 +346,20 @@ fn nest<'a, 'gcx, 'tcx, E>(
         })
     }
 
+    /// Like `print_def_path` but for value paths.
+    fn print_value_path(
+        self: PrintCx<'_, '_, 'tcx, Self>,
+        def_id: DefId,
+        substs: Option<SubstsRef<'tcx>>,
+    ) -> Result<Self::Path, Self::Error> {
+        self.print_def_path(def_id, substs, iter::empty())
+    }
+
     /// Print `<...>` around what `f` prints.
     fn generic_delimiters<'gcx, 'tcx>(
-        mut self: PrintCx<'_, 'gcx, 'tcx, Self>,
+        self: PrintCx<'_, 'gcx, 'tcx, Self>,
         f: impl FnOnce(PrintCx<'_, 'gcx, 'tcx, Self>) -> Result<Self, Self::Error>,
-    ) -> Result<Self, Self::Error> {
-        write!(self.printer, "<")?;
-        let mut printer = f(self)?;
-        write!(printer, ">")?;
-        Ok(printer)
-    }
+    ) -> Result<Self, Self::Error>;
 
     /// Return `true` if the region should be printed in path generic args
     /// even when it's `'_`, such as in e.g. `Foo<'_, '_, '_>`.
@@ -414,8 +414,8 @@ pub fn def_path_str(self, def_id: DefId) -> String {
         let ns = self.guess_def_namespace(def_id);
         debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns);
         let mut s = String::new();
-        let _ = PrintCx::with(self, FmtPrinter::new(&mut s), |cx| {
-            cx.print_def_path(def_id, None, ns, iter::empty())
+        let _ = PrintCx::with(self, FmtPrinter::new(&mut s, ns), |cx| {
+            cx.print_def_path(def_id, None, iter::empty())
         });
         s
     }
@@ -426,10 +426,9 @@ pub fn default_print_def_path(
         self,
         def_id: DefId,
         substs: Option<SubstsRef<'tcx>>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<P::Path, P::Error> {
-        debug!("default_print_def_path: def_id={:?}, substs={:?}, ns={:?}", def_id, substs, ns);
+        debug!("default_print_def_path: def_id={:?}, substs={:?}", def_id, substs);
         let key = self.tcx.def_key(def_id);
         debug!("default_print_def_path: key={:?}", key);
 
@@ -449,7 +448,7 @@ pub fn default_print_def_path(
                 if let Some(substs) = substs {
                     impl_trait_ref = impl_trait_ref.subst(self.tcx, substs);
                 }
-                self.print_impl_path(def_id, substs, ns, self_ty, impl_trait_ref)
+                self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
             }
 
             _ => {
@@ -467,12 +466,12 @@ pub fn default_print_def_path(
                             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);
-                            cx.path_qualified(trait_ref.self_ty(), Some(trait_ref), ns)
+                            cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
                         } else {
-                            cx.print_def_path(parent_def_id, substs, ns, iter::empty())
+                            cx.print_def_path(parent_def_id, substs, iter::empty())
                         }
                     } else {
-                        cx.print_def_path(parent_def_id, None, ns, iter::empty())
+                        cx.print_def_path(parent_def_id, None, iter::empty())
                     }
                 };
                 let print_path = |cx: PrintCx<'_, 'gcx, 'tcx, P>| {
@@ -492,7 +491,7 @@ pub fn default_print_def_path(
                 if let (Some(generics), Some(substs)) = (generics, substs) {
                     let has_own_self = generics.has_self && generics.parent_count == 0;
                     let params = &generics.params[has_own_self as usize..];
-                    self.path_generic_args(print_path, params, substs, ns, projections)
+                    self.path_generic_args(print_path, params, substs, projections)
                 } else {
                     print_path(self)
                 }
@@ -504,7 +503,6 @@ fn default_print_impl_path(
         self,
         impl_def_id: DefId,
         _substs: Option<SubstsRef<'tcx>>,
-        ns: Namespace,
         self_ty: Ty<'tcx>,
         impl_trait_ref: Option<ty::TraitRef<'tcx>>,
     ) -> Result<P::Path, P::Error> {
@@ -531,14 +529,14 @@ fn default_print_impl_path(
             // trait-type, then fallback to a format that identifies
             // the module more clearly.
             self.path_append_impl(
-                |cx| cx.print_def_path(parent_def_id, None, ns, iter::empty()),
+                |cx| cx.print_def_path(parent_def_id, None, iter::empty()),
                 self_ty,
                 impl_trait_ref,
             )
         } else {
             // Otherwise, try to give a good form that would be valid language
             // syntax. Preferably using associated item notation.
-            self.path_qualified(self_ty, impl_trait_ref, ns)
+            self.path_qualified(self_ty, impl_trait_ref)
         }
     }
 }
@@ -594,14 +592,16 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
 pub struct FmtPrinter<F: fmt::Write> {
     pub(crate) fmt: F,
     empty: bool,
+    in_value: bool,
     pub region_highlight_mode: RegionHighlightMode,
 }
 
 impl<F: fmt::Write> FmtPrinter<F> {
-    pub fn new(fmt: F) -> Self {
+    pub fn new(fmt: F, ns: Namespace) -> Self {
         FmtPrinter {
             fmt,
             empty: true,
+            in_value: ns == Namespace::ValueNS,
             region_highlight_mode: RegionHighlightMode::default(),
         }
     }
@@ -645,7 +645,7 @@ fn try_print_visible_def_path(
                 }) => {
                     debug!("try_print_visible_def_path: def_id={:?}", def_id);
                     return Ok((if !span.is_dummy() {
-                        self.print_def_path(def_id, None, Namespace::TypeNS, iter::empty())?
+                        self.print_def_path(def_id, None, iter::empty())?
                     } else {
                         self.path_crate(cnum)?
                     }, true));
@@ -760,20 +760,13 @@ pub fn pretty_path_qualified(
         self,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
-        ns: Namespace,
     ) -> Result<P::Path, P::Error> {
         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::Adt(..) | ty::Foreign(_) |
                 ty::Bool | ty::Char | ty::Str |
                 ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
                     return self_ty.print_display(self);
@@ -787,12 +780,7 @@ pub fn pretty_path_qualified(
             nest!(cx, |cx| self_ty.print_display(cx));
             if let Some(trait_ref) = trait_ref {
                 write!(cx.printer, " as ")?;
-                nest!(cx, |cx| cx.print_def_path(
-                    trait_ref.def_id,
-                    Some(trait_ref.substs),
-                    Namespace::TypeNS,
-                    iter::empty(),
-                ));
+                nest!(cx, |cx| trait_ref.print_display(cx));
             }
             Ok(cx.printer)
         })
@@ -827,7 +815,6 @@ pub fn pretty_path_generic_args(
         ) -> Result<P::Path, P::Error>,
         params: &[ty::GenericParamDef],
         substs: SubstsRef<'tcx>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<P::Path, P::Error> {
         nest!(self, |cx| print_prefix(cx));
@@ -878,11 +865,6 @@ pub fn pretty_path_generic_args(
             return Ok(self.printer);
         }
 
-        // FIXME(eddyb) move this into `generic_delimiters`.
-        if ns == Namespace::ValueNS {
-            write!(self.printer, "::")?;
-        }
-
         self.generic_delimiters(|mut cx| {
             let mut empty = true;
             let mut maybe_comma = |cx: &mut Self| {
@@ -950,7 +932,6 @@ fn print_def_path(
         mut self: PrintCx<'_, '_, 'tcx, Self>,
         def_id: DefId,
         substs: Option<SubstsRef<'tcx>>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<Self::Path, Self::Error> {
         // FIXME(eddyb) avoid querying `tcx.generics_of` and `tcx.def_key`
@@ -967,7 +948,7 @@ fn print_def_path(
                 return if let (Some(generics), Some(substs)) = (generics, substs) {
                     let has_own_self = generics.has_self && generics.parent_count == 0;
                     let params = &generics.params[has_own_self as usize..];
-                    self.path_generic_args(|cx| Ok(cx.printer), params, substs, ns, projections)
+                    self.path_generic_args(|cx| Ok(cx.printer), params, substs, projections)
                 } else {
                     Ok(self.printer)
                 };
@@ -992,13 +973,13 @@ fn print_def_path(
                 let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
                 let span = self.tcx.def_span(def_id);
                 return self.path_append(
-                    |cx| cx.print_def_path(parent_def_id, None, ns, iter::empty()),
+                    |cx| cx.print_def_path(parent_def_id, None, iter::empty()),
                     &format!("<impl at {:?}>", span),
                 );
             }
         }
 
-        self.default_print_def_path(def_id, substs, ns, projections)
+        self.default_print_def_path(def_id, substs, projections)
     }
 
     fn print_region(
@@ -1103,9 +1084,8 @@ fn path_qualified(
         self: PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
-        ns: Namespace,
     ) -> Result<Self::Path, Self::Error> {
-        self.pretty_path_qualified(self_ty, trait_ref, ns)
+        self.pretty_path_qualified(self_ty, trait_ref)
     }
 
     fn path_append_impl<'gcx, 'tcx>(
@@ -1119,7 +1099,9 @@ fn path_append_impl<'gcx, 'tcx>(
         self.pretty_path_append_impl(|cx| {
             let mut printer = print_prefix(cx)?;
 
-            if !printer.empty {
+            // HACK(eddyb) this accounts for `generic_delimiters`
+            // printing `::<` instead of `<` if `in_value` is set.
+            if !printer.empty && !printer.in_value {
                 write!(printer, "::")?;
             }
 
@@ -1153,10 +1135,9 @@ fn path_generic_args<'gcx, 'tcx>(
         ) -> Result<Self::Path, Self::Error>,
         params: &[ty::GenericParamDef],
         substs: SubstsRef<'tcx>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     ) -> Result<Self::Path, Self::Error> {
-        self.pretty_path_generic_args(print_prefix, params, substs, ns, projections)
+        self.pretty_path_generic_args(print_prefix, params, substs, projections)
     }
 }
 
@@ -1179,6 +1160,36 @@ fn nest<'a, 'gcx, 'tcx, E>(
         })
     }
 
+    fn print_value_path(
+        mut self: PrintCx<'_, '_, 'tcx, Self>,
+        def_id: DefId,
+        substs: Option<SubstsRef<'tcx>>,
+    ) -> Result<Self::Path, Self::Error> {
+        let was_in_value = std::mem::replace(&mut self.printer.in_value, true);
+        let mut printer = self.print_def_path(def_id, substs, iter::empty())?;
+        printer.in_value = was_in_value;
+
+        Ok(printer)
+    }
+
+    fn generic_delimiters<'gcx, 'tcx>(
+        mut self: PrintCx<'_, 'gcx, 'tcx, Self>,
+        f: impl FnOnce(PrintCx<'_, 'gcx, 'tcx, Self>) -> Result<Self, Self::Error>,
+    ) -> Result<Self, Self::Error> {
+        if !self.printer.empty && self.printer.in_value {
+            write!(self.printer, "::<")?;
+        } else {
+            write!(self.printer, "<")?;
+        }
+
+        let was_in_value = std::mem::replace(&mut self.printer.in_value, false);
+        let mut printer = f(self)?;
+        printer.in_value = was_in_value;
+
+        write!(printer, ">")?;
+        Ok(printer)
+    }
+
     fn always_print_region_in_paths(
         self: &PrintCx<'_, '_, '_, Self>,
         region: ty::Region<'_>,
index f42865f55ec8425c75bd14492d5cf32aebea6284..204a9574a64f0506aa92c066a52f3be3701a0f9b 100644 (file)
@@ -17,7 +17,7 @@
 macro_rules! gen_display_debug_body {
     ( $with:path ) => {
         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-            PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
+            PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::TypeNS), |cx| {
                 $with(&cx.tcx.lift(self).expect("could not lift for printing"), cx)?;
                 Ok(())
             })
@@ -262,9 +262,9 @@ pub fn parameterized<F: fmt::Write>(
     substs: SubstsRef<'_>,
     ns: Namespace,
 ) -> fmt::Result {
-    PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
+    PrintCx::with_tls_tcx(FmtPrinter::new(f, ns), |cx| {
         let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
-        cx.print_def_path(did, Some(substs), ns, iter::empty())?;
+        cx.print_def_path(did, Some(substs), iter::empty())?;
         Ok(())
     })
 }
@@ -284,12 +284,7 @@ pub fn parameterized<F: fmt::Write>(
                     if let ty::Tuple(ref args) = principal.substs.type_at(0).sty {
                         let mut projections = self.projection_bounds();
                         if let (Some(proj), None) = (projections.next(), projections.next()) {
-                            nest!(|cx| cx.print_def_path(
-                                principal.def_id,
-                                None,
-                                Namespace::TypeNS,
-                                iter::empty(),
-                            ));
+                            nest!(|cx| cx.print_def_path(principal.def_id, None, iter::empty()));
                             nest!(|cx| cx.fn_sig(args, false, proj.ty));
                             resugared_principal = true;
                         }
@@ -303,7 +298,6 @@ pub fn parameterized<F: fmt::Write>(
                     nest!(|cx| cx.print_def_path(
                         principal.def_id,
                         Some(principal.substs),
-                        Namespace::TypeNS,
                         self.projection_bounds(),
                     ));
                 }
@@ -332,12 +326,7 @@ pub fn parameterized<F: fmt::Write>(
                 }
                 first = false;
 
-                nest!(|cx| cx.print_def_path(
-                    def_id,
-                    None,
-                    Namespace::TypeNS,
-                    iter::empty(),
-                ));
+                nest!(|cx| cx.print_def_path(def_id, None, iter::empty()));
             }
         }
     }
@@ -360,13 +349,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl fmt::Debug for ty::TraitDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
-            cx.print_def_path(
-                self.def_id,
-                None,
-                Namespace::TypeNS,
-                iter::empty(),
-            )?;
+        PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::TypeNS), |cx| {
+            cx.print_def_path(self.def_id, None, iter::empty())?;
             Ok(())
         })
     }
@@ -374,13 +358,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl fmt::Debug for ty::AdtDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
-            cx.print_def_path(
-                self.did,
-                None,
-                Namespace::TypeNS,
-                iter::empty(),
-            )?;
+        PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::TypeNS), |cx| {
+            cx.print_def_path(self.did, None, iter::empty())?;
             Ok(())
         })
     }
@@ -396,7 +375,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl fmt::Debug for ty::UpvarId {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        PrintCx::with_tls_tcx(FmtPrinter::new(f), |mut cx| {
+        PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |mut cx| {
             define_scoped_cx!(cx);
             p!(write("UpvarId({:?};`{}`;{:?})",
                 self.var_path.hir_id,
@@ -671,15 +650,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 define_print! {
     ('tcx) ty::TraitRef<'tcx>, (self, cx) {
         display {
-            nest!(|cx| cx.print_def_path(
-                self.def_id,
-                Some(self.substs),
-                Namespace::TypeNS,
-                iter::empty(),
-            ));
+            nest!(|cx| cx.print_def_path(self.def_id, Some(self.substs), iter::empty()));
         }
         debug {
-            nest!(|cx| cx.path_qualified(self.self_ty(), Some(*self), Namespace::TypeNS));
+            nest!(|cx| cx.path_qualified(self.self_ty(), Some(*self)));
         }
     }
 }
@@ -730,12 +704,7 @@ pub fn pretty_print_type(
             ty::FnDef(def_id, substs) => {
                 let sig = self.tcx.fn_sig(def_id).subst(self.tcx, substs);
                 p!(print(sig), write(" {{"));
-                nest!(|cx| cx.print_def_path(
-                    def_id,
-                    Some(substs),
-                    Namespace::ValueNS,
-                    iter::empty(),
-                ));
+                nest!(|cx| cx.print_value_path(def_id, Some(substs)));
                 p!(write("}}"))
             }
             ty::FnPtr(ref bare_fn) => {
@@ -758,12 +727,7 @@ pub fn pretty_print_type(
                 }
             }
             ty::Adt(def, substs) => {
-                nest!(|cx| cx.print_def_path(
-                    def.did,
-                    Some(substs),
-                    Namespace::TypeNS,
-                    iter::empty(),
-                ));
+                nest!(|cx| cx.print_def_path(def.did, Some(substs), iter::empty()));
             }
             ty::Dynamic(data, r) => {
                 let print_r = self.print_region_outputs_anything(r);
@@ -776,12 +740,7 @@ pub fn pretty_print_type(
                 }
             }
             ty::Foreign(def_id) => {
-                nest!(|cx| cx.print_def_path(
-                    def_id,
-                    None,
-                    Namespace::TypeNS,
-                    iter::empty(),
-                ));
+                nest!(|cx| cx.print_def_path(def_id, None, iter::empty()));
             }
             ty::Projection(ref data) => p!(print(data)),
             ty::UnnormalizedProjection(ref data) => {
@@ -1074,12 +1033,7 @@ pub fn pretty_print_type(
 define_print! {
     ('tcx) ty::ProjectionTy<'tcx>, (self, cx) {
         display {
-            nest!(|cx| cx.print_def_path(
-                self.item_def_id,
-                Some(self.substs),
-                Namespace::TypeNS,
-                iter::empty(),
-            ));
+            nest!(|cx| cx.print_def_path(self.item_def_id, Some(self.substs), iter::empty()));
         }
     }
 }
@@ -1108,32 +1062,17 @@ pub fn pretty_print_type(
                 ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")),
                 ty::Predicate::ObjectSafe(trait_def_id) => {
                     p!(write("the trait `"));
-                    nest!(|cx| cx.print_def_path(
-                        trait_def_id,
-                        None,
-                        Namespace::TypeNS,
-                        iter::empty(),
-                    ));
+                    nest!(|cx| cx.print_def_path(trait_def_id, None, iter::empty()));
                     p!(write("` is object-safe"))
                 }
                 ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
                     p!(write("the closure `"));
-                    nest!(|cx| cx.print_def_path(
-                        closure_def_id,
-                        None,
-                        Namespace::ValueNS,
-                        iter::empty(),
-                    ));
+                    nest!(|cx| cx.print_value_path(closure_def_id, None));
                     p!(write("` implements the trait `{}`", kind))
                 }
                 ty::Predicate::ConstEvaluatable(def_id, substs) => {
                     p!(write("the constant `"));
-                    nest!(|cx| cx.print_def_path(
-                        def_id,
-                        Some(substs),
-                        Namespace::ValueNS,
-                        iter::empty(),
-                    ));
+                    nest!(|cx| cx.print_value_path(def_id, Some(substs)));
                     p!(write("` can be evaluated"))
                 }
             }
index 40dc22309664a1a90d06379ae5f3d90fde1073fa..3c8bd0dd01b47477185d85f3b126afaeeec230e8 100644 (file)
@@ -87,7 +87,6 @@
 //! virtually impossible. Thus, symbol hash generation exclusively relies on
 //! DefPaths which are much more robust in the face of changes to the code base.
 
-use rustc::hir::def::Namespace;
 use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use rustc::hir::Node;
 use rustc::hir::CodegenFnAttrFlags;
@@ -226,7 +225,7 @@ fn get_symbol_hash<'a, 'tcx>(
 
 fn def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName {
     PrintCx::with(tcx, SymbolPath::new(tcx), |cx| {
-        cx.print_def_path(def_id, None, Namespace::ValueNS, iter::empty())
+        cx.print_def_path(def_id, None, iter::empty())
             .unwrap()
             .into_interned()
     })
@@ -437,9 +436,8 @@ fn path_qualified(
         self: PrintCx<'_, '_, 'tcx, Self>,
         self_ty: Ty<'tcx>,
         trait_ref: Option<ty::TraitRef<'tcx>>,
-        ns: Namespace,
     ) -> Result<Self::Path, Self::Error> {
-        self.pretty_path_qualified(self_ty, trait_ref, ns)
+        self.pretty_path_qualified(self_ty, trait_ref)
     }
 
     fn path_append_impl<'gcx, 'tcx>(
@@ -482,10 +480,9 @@ fn path_generic_args<'gcx, 'tcx>(
         ) -> Result<Self::Path, Self::Error>,
         params: &[ty::GenericParamDef],
         substs: SubstsRef<'tcx>,
-        ns: Namespace,
         projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
     )  -> Result<Self::Path, Self::Error> {
-        self.pretty_path_generic_args(print_prefix, params, substs, ns, projections)
+        self.pretty_path_generic_args(print_prefix, params, substs, projections)
     }
 }
 
index 9a80415827e89ff040fa9c060117d9b986596c58..7a92a507ec160c0198cdf88e284d3f731dd49fbd 100644 (file)
@@ -3,6 +3,7 @@
 use crate::borrow_check::prefixes::IsPrefixOf;
 use crate::borrow_check::WriteKind;
 use rustc::hir;
+use rustc::hir::def::Namespace;
 use rustc::hir::def_id::DefId;
 use rustc::middle::region::ScopeTree;
 use rustc::mir::{
@@ -2325,7 +2326,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
     /// name where required.
     fn get_name_for_ty(&self, ty: ty::Ty<'tcx>, counter: usize) -> String {
         let mut s = String::new();
-        let mut printer = ty::print::FmtPrinter::new(&mut s);
+        let mut printer = ty::print::FmtPrinter::new(&mut s, Namespace::TypeNS);
 
         // We need to add synthesized lifetimes where appropriate. We do
         // this by hooking into the pretty printer and telling it to label the
@@ -2350,7 +2351,7 @@ fn get_name_for_ty(&self, ty: ty::Ty<'tcx>, counter: usize) -> String {
     /// synthesized lifetime name where required.
     fn get_region_name_for_ty(&self, ty: ty::Ty<'tcx>, counter: usize) -> String {
         let mut s = String::new();
-        let mut printer = ty::print::FmtPrinter::new(&mut s);
+        let mut printer = ty::print::FmtPrinter::new(&mut s, Namespace::TypeNS);
 
         let region = match ty.sty {
             ty::TyKind::Ref(region, _, _) => {
index 13db78cc803aa278202360a2b2772c9ae3febbbd..02b8291369d9d82c72eab61b4d47be5ed85fc0cf 100644 (file)
@@ -18,7 +18,7 @@
 use rustc::middle::stability;
 use rustc::mir::interpret::GlobalId;
 use rustc::hir::{self, GenericArg, HirVec};
-use rustc::hir::def::{self, Def, CtorKind, Namespace};
+use rustc::hir::def::{self, Def, CtorKind};
 use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc::ty::subst::{InternalSubsts, SubstsRef};
 use rustc::ty::{self, DefIdTree, TyCtxt, Region, RegionVid, Ty, AdtKind};
@@ -4260,7 +4260,6 @@ fn path_qualified(
             self: PrintCx<'_, '_, 'tcx, Self>,
             self_ty: Ty<'tcx>,
             trait_ref: Option<ty::TraitRef<'tcx>>,
-            _ns: Namespace,
         ) -> Result<Self::Path, Self::Error> {
             // This shouldn't ever be needed, but just in case:
             Ok(vec![match trait_ref {
@@ -4307,7 +4306,6 @@ fn path_generic_args<'gcx, 'tcx>(
             ) -> Result<Self::Path, Self::Error>,
             _params: &[ty::GenericParamDef],
             _substs: SubstsRef<'tcx>,
-            _ns: Namespace,
             _projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
         ) -> Result<Self::Path, Self::Error> {
             print_prefix(self)
@@ -4315,7 +4313,7 @@ fn path_generic_args<'gcx, 'tcx>(
     }
 
     let names = PrintCx::with(tcx, AbsolutePathPrinter, |cx| {
-        cx.print_def_path(def_id, None, Namespace::TypeNS, iter::empty()).unwrap()
+        cx.print_def_path(def_id, None, iter::empty()).unwrap()
     });
 
     hir::Path {