From: Eduard-Mihai Burtescu Date: Mon, 14 Jan 2019 21:40:53 +0000 (+0200) Subject: rustc: don't pass Namespace explicitly, but rather track it in FmtPrinter. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5211e37b1dd6b7fc26d919941e958bce8f5815a0;p=rust.git rustc: don't pass Namespace explicitly, but rather track it in FmtPrinter. --- diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 863e10846f4..ad24e15b45a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -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>, - _ns: Namespace, ) -> Result { Err(NonTrivialPath) } @@ -517,7 +515,6 @@ fn path_generic_args<'gcx, 'tcx>( ) -> Result, _params: &[ty::GenericParamDef], _substs: SubstsRef<'tcx>, - _ns: Namespace, _projections: impl Iterator>, ) -> Result { 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()) }) }; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 26deecfdbf0..2fabbbeadbd 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -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; } diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 65fcc69a338..39ab244dae1 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -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| { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 70ebb7111ef..c2cafac2d55 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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 { diff --git a/src/librustc/ty/print.rs b/src/librustc/ty/print.rs index 447f02f42d2..a94ae0123d8 100644 --- a/src/librustc/ty/print.rs +++ b/src/librustc/ty/print.rs @@ -258,20 +258,18 @@ fn print_def_path( self: PrintCx<'_, '_, 'tcx, Self>, def_id: DefId, substs: Option>, - ns: Namespace, projections: impl Iterator>, ) -> Result { - 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>, - ns: Namespace, self_ty: Ty<'tcx>, trait_ref: Option>, ) -> Result { - 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>, - ns: Namespace, ) -> Result; fn path_append_impl<'gcx, 'tcx>( @@ -317,7 +314,6 @@ fn path_generic_args<'gcx, 'tcx>( ) -> Result, params: &[ty::GenericParamDef], substs: SubstsRef<'tcx>, - ns: Namespace, projections: impl Iterator>, ) -> Result; } @@ -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>, + ) -> Result { + 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, - ) -> Result { - write!(self.printer, "<")?; - let mut printer = f(self)?; - write!(printer, ">")?; - Ok(printer) - } + ) -> Result; /// 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>, - ns: Namespace, projections: impl Iterator>, ) -> Result { - 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>, - ns: Namespace, self_ty: Ty<'tcx>, impl_trait_ref: Option>, ) -> Result { @@ -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 { pub struct FmtPrinter { pub(crate) fmt: F, empty: bool, + in_value: bool, pub region_highlight_mode: RegionHighlightMode, } impl FmtPrinter { - 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>, - ns: Namespace, ) -> Result { if trait_ref.is_none() { // Inherent impls. Try to print `Foo::bar` for an inherent // impl on `Foo`, but fallback to `::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, params: &[ty::GenericParamDef], substs: SubstsRef<'tcx>, - ns: Namespace, projections: impl Iterator>, ) -> Result { 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>, - ns: Namespace, projections: impl Iterator>, ) -> Result { // 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!("", 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>, - ns: Namespace, ) -> Result { - 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, params: &[ty::GenericParamDef], substs: SubstsRef<'tcx>, - ns: Namespace, projections: impl Iterator>, ) -> Result { - 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>, + ) -> Result { + 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, + ) -> Result { + 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<'_>, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index f42865f55ec..204a9574a64 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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( 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( 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( nest!(|cx| cx.print_def_path( principal.def_id, Some(principal.substs), - Namespace::TypeNS, self.projection_bounds(), )); } @@ -332,12 +326,7 @@ pub fn parameterized( } 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")) } } diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 40dc2230966..3c8bd0dd01b 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -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>, - ns: Namespace, ) -> Result { - 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, params: &[ty::GenericParamDef], substs: SubstsRef<'tcx>, - ns: Namespace, projections: impl Iterator>, ) -> Result { - self.pretty_path_generic_args(print_prefix, params, substs, ns, projections) + self.pretty_path_generic_args(print_prefix, params, substs, projections) } } diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 9a80415827e..7a92a507ec1 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -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, _, _) => { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 13db78cc803..02b8291369d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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>, - _ns: Namespace, ) -> Result { // 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, _params: &[ty::GenericParamDef], _substs: SubstsRef<'tcx>, - _ns: Namespace, _projections: impl Iterator>, ) -> Result { 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 {