From a54a41ce47c149fd6587182a4ab87a146844f939 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 3 Feb 2019 12:59:37 +0200 Subject: rustc: provide DisambiguatedDefPathData in ty::print. --- src/librustc_codegen_utils/symbol_names.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/librustc_codegen_utils') diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 262ba8a1c74..0fa935199f9 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -90,7 +90,7 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::Node; use rustc::hir::CodegenFnAttrFlags; -use rustc::hir::map::definitions::DefPathData; +use rustc::hir::map::{DefPathData, DisambiguatedDefPathData}; use rustc::ich::NodeIdHashingMode; use rustc::ty::print::{PrettyPrinter, Printer, Print}; use rustc::ty::query::Providers; @@ -492,11 +492,23 @@ impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> { fn path_append_impl( self, print_prefix: impl FnOnce(Self) -> Result, + _disambiguated_data: &DisambiguatedDefPathData, self_ty: Ty<'tcx>, trait_ref: Option>, ) -> Result { self.pretty_path_append_impl( - |cx| cx.path_append(print_prefix, ""), + |mut cx| { + cx = print_prefix(cx)?; + + if cx.keep_within_component { + // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it. + cx.write_str("::")?; + } else { + cx.path.finalize_pending_component(); + } + + Ok(cx) + }, self_ty, trait_ref, ) @@ -504,10 +516,16 @@ impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> { fn path_append( mut self, print_prefix: impl FnOnce(Self) -> Result, - text: &str, + disambiguated_data: &DisambiguatedDefPathData, ) -> Result { self = print_prefix(self)?; + // Skip `::{{constructor}}` on tuple/unit structs. + match disambiguated_data.data { + DefPathData::StructCtor => return Ok(self), + _ => {} + } + if self.keep_within_component { // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it. self.write_str("::")?; @@ -515,7 +533,7 @@ impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> { self.path.finalize_pending_component(); } - self.write_str(text)?; + self.write_str(&disambiguated_data.data.as_interned_str().as_str())?; Ok(self) } fn path_generic_args( -- cgit 1.4.1-3-g733a5