From f1878d19faf9472f8860a3ff4fe605fdf93cef2c Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 31 Aug 2020 18:11:44 +0100 Subject: Move from {{closure}}#0 syntax to {closure#0} for (def) path components --- compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs index d1a55335c44..835d0d2e12d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs @@ -7,7 +7,8 @@ use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::DIScope; use rustc_hir::def_id::DefId; -use rustc_hir::definitions::DefPathData; +use rustc_hir::definitions::{DefPathData, DefPathDataName}; +use rustc_span::symbol::Symbol; pub fn mangled_name_of_instance<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, @@ -29,7 +30,12 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { let namespace_name = match def_key.disambiguated_data.data { DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), - data => data.as_symbol(), + data => match data.get_name() { + DefPathDataName::Named(name) => name, + DefPathDataName::Anon { namespace } => { + Symbol::intern(&format!("{{{{{}}}}}", namespace)) + } + }, }; let namespace_name = namespace_name.as_str(); -- cgit 1.4.1-3-g733a5 From 657ecdb75e2a9f8e8295bc75d9fe810f02605130 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 1 Sep 2020 00:42:30 +0100 Subject: Rename `DefPathData::get_name()` to `DefPathData::name()` --- compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs | 2 +- compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs | 2 +- compiler/rustc_hir/src/definitions.rs | 2 +- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_middle/src/ty/query/profiling_support.rs | 2 +- compiler/rustc_mir/src/monomorphize/partitioning/default.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs index 835d0d2e12d..661d13ead83 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs @@ -30,7 +30,7 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { let namespace_name = match def_key.disambiguated_data.data { DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), - data => match data.get_name() { + data => match data.name() { DefPathDataName::Named(name) => name, DefPathDataName::Anon { namespace } => { Symbol::intern(&format!("{{{{{}}}}}", namespace)) diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index e227f9df000..5642cc526ae 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -232,7 +232,7 @@ pub fn push_debuginfo_type_name<'tcx>( output.push_str(&tcx.crate_name(def_id.krate).as_str()); for path_element in tcx.def_path(def_id).data { output.push_str("::"); - match path_element.data.get_name() { + match path_element.data.name() { DefPathDataName::Named(name) => output.push_str(&name.as_str()), DefPathDataName::Anon { namespace } => { write!(output, "{{{{{}}}}}", namespace).unwrap() diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index ae2ce6f176a..5d1c6b78f36 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -157,7 +157,7 @@ pub struct DisambiguatedDefPathData { impl DisambiguatedDefPathData { pub fn fmt_maybe_verbose(&self, writer: &mut impl Write, verbose: bool) -> fmt::Result { - match self.data.get_name() { + match self.data.name() { DefPathDataName::Named(name) => { if Ident::with_dummy_span(name).is_raw_guess() { writer.write_str("r#")?; diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index e4b72847638..776c3c83e02 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -846,7 +846,7 @@ impl<'tcx> LateContext<'tcx> { return Ok(path); } - path.push(match disambiguated_data.data.get_name() { + path.push(match disambiguated_data.data.name() { DefPathDataName::Named(name) => name, DefPathDataName::Anon { namespace } => { Symbol::intern(&format!("{{{{{}}}}}", namespace)) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 7ec14d43892..0e1d5c8fee7 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1498,7 +1498,7 @@ impl Printer<'tcx> for FmtPrinter<'_, 'tcx, F> { // FIXME(eddyb) `name` should never be empty, but it // currently is for `extern { ... }` "foreign modules". - let name = disambiguated_data.data.get_name(); + let name = disambiguated_data.data.name(); if name != DefPathDataName::Named(kw::Invalid) { if !self.empty_path { write!(self, "::")?; diff --git a/compiler/rustc_middle/src/ty/query/profiling_support.rs b/compiler/rustc_middle/src/ty/query/profiling_support.rs index cecb58eb024..f8269fe372e 100644 --- a/compiler/rustc_middle/src/ty/query/profiling_support.rs +++ b/compiler/rustc_middle/src/ty/query/profiling_support.rs @@ -66,7 +66,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { end_index = 3; } other => { - name = match other.get_name() { + name = match other.name() { DefPathDataName::Named(name) => { dis = ""; end_index = 3; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs index c9622df099f..62805a973f5 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs @@ -355,7 +355,7 @@ fn compute_codegen_unit_name( *cache.entry((cgu_def_id, volatile)).or_insert_with(|| { let def_path = tcx.def_path(cgu_def_id); - let components = def_path.data.iter().map(|part| match part.data.get_name() { + let components = def_path.data.iter().map(|part| match part.data.name() { DefPathDataName::Named(name) => name, DefPathDataName::Anon { namespace } => { Symbol::intern(&format!("{{{{{}}}}}", namespace)) -- cgit 1.4.1-3-g733a5 From bb8e1764bb31bc63a6b61f446e28bb567015de01 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 1 Sep 2020 13:11:28 +0100 Subject: Simplify some match statements on `DefPathDataName' --- compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs | 9 ++------- compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs | 9 +-------- compiler/rustc_lint/src/context.rs | 9 ++------- 3 files changed, 5 insertions(+), 22 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs index 661d13ead83..512fc87905e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs @@ -7,7 +7,7 @@ use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::DIScope; use rustc_hir::def_id::DefId; -use rustc_hir::definitions::{DefPathData, DefPathDataName}; +use rustc_hir::definitions::DefPathData; use rustc_span::symbol::Symbol; pub fn mangled_name_of_instance<'a, 'tcx>( @@ -30,12 +30,7 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { let namespace_name = match def_key.disambiguated_data.data { DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), - data => match data.name() { - DefPathDataName::Named(name) => name, - DefPathDataName::Anon { namespace } => { - Symbol::intern(&format!("{{{{{}}}}}", namespace)) - } - }, + data => Symbol::intern(&data.to_string()), }; let namespace_name = namespace_name.as_str(); diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 5642cc526ae..45ecb793387 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -3,7 +3,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::definitions::DefPathDataName; use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt}; use std::fmt::Write; @@ -231,13 +230,7 @@ pub fn push_debuginfo_type_name<'tcx>( if qualified { output.push_str(&tcx.crate_name(def_id.krate).as_str()); for path_element in tcx.def_path(def_id).data { - output.push_str("::"); - match path_element.data.name() { - DefPathDataName::Named(name) => output.push_str(&name.as_str()), - DefPathDataName::Anon { namespace } => { - write!(output, "{{{{{}}}}}", namespace).unwrap() - } - } + write!(output, "::{}", path_element.data).unwrap(); } } else { output.push_str(&tcx.item_name(def_id).as_str()); diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 776c3c83e02..7a3035e5b46 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -26,7 +26,7 @@ use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; -use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; +use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::stability; @@ -846,12 +846,7 @@ impl<'tcx> LateContext<'tcx> { return Ok(path); } - path.push(match disambiguated_data.data.name() { - DefPathDataName::Named(name) => name, - DefPathDataName::Anon { namespace } => { - Symbol::intern(&format!("{{{{{}}}}}", namespace)) - } - }); + path.push(Symbol::intern(&disambiguated_data.data.to_string())); Ok(path) } -- cgit 1.4.1-3-g733a5 From 35bad3edbfd99ecf8698ac917a2582109bac5503 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 23 Sep 2020 23:38:38 +0100 Subject: Address review comment --- compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs | 14 ++++++++++---- compiler/rustc_hir/src/definitions.rs | 9 +++++---- compiler/rustc_middle/src/hir/map/collector.rs | 8 +++++--- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/query/profiling_support.rs | 10 ++++++---- compiler/rustc_passes/src/hir_id_validator.rs | 8 ++++---- 6 files changed, 31 insertions(+), 20 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs index 512fc87905e..9945d4f4282 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs @@ -8,7 +8,6 @@ use crate::llvm; use crate::llvm::debuginfo::DIScope; use rustc_hir::def_id::DefId; use rustc_hir::definitions::DefPathData; -use rustc_span::symbol::Symbol; pub fn mangled_name_of_instance<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, @@ -28,11 +27,18 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { .parent .map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent })); + let crate_name_as_str; + let name_to_string; let namespace_name = match def_key.disambiguated_data.data { - DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), - data => Symbol::intern(&data.to_string()), + DefPathData::CrateRoot => { + crate_name_as_str = cx.tcx.crate_name(def_id.krate).as_str(); + &*crate_name_as_str + } + data => { + name_to_string = data.to_string(); + &*name_to_string + } }; - let namespace_name = namespace_name.as_str(); let scope = unsafe { llvm::LLVMRustDIBuilderCreateNameSpace( diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 5d1c6b78f36..74c91f8a859 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -162,10 +162,10 @@ impl DisambiguatedDefPathData { if Ident::with_dummy_span(name).is_raw_guess() { writer.write_str("r#")?; } - if self.disambiguator == 0 || !verbose { - writer.write_str(&name.as_str()) - } else { + if verbose && self.disambiguator != 0 { write!(writer, "{}#{}", name, self.disambiguator) + } else { + writer.write_str(&name.as_str()) } } DefPathDataName::Anon { namespace } => { @@ -224,7 +224,7 @@ impl DefPath { /// Returns a string representation of the `DefPath` without /// the crate-prefix. This method is useful if you don't have /// a `TyCtxt` available. - pub fn to_string_no_crate(&self) -> String { + pub fn to_string_no_crate_verbose(&self) -> String { let mut s = String::with_capacity(self.data.len() * 16); for component in &self.data { @@ -466,6 +466,7 @@ impl fmt::Display for DefPathData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.name() { DefPathDataName::Named(name) => f.write_str(&name.as_str()), + // FIXME(#70334): this will generate legacy {{closure}}, {{impl}}, etc DefPathDataName::Anon { namespace } => write!(f, "{{{{{}}}}}", namespace), } } diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index dce06a5f7ee..d6869ab8875 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -244,7 +244,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { if cfg!(debug_assertions) { if hir_id.owner != self.current_dep_node_owner { let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) { - Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate(), + Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate_verbose(), None => format!("{:?}", node), }; @@ -254,9 +254,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", self.source_map.span_to_string(span), node_str, - self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(), + self.definitions + .def_path(self.current_dep_node_owner) + .to_string_no_crate_verbose(), self.current_dep_node_owner, - self.definitions.def_path(hir_id.owner).to_string_no_crate(), + self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(), hir_id.owner, ) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ccc8ffd9a9c..22c3fd37be1 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1272,7 +1272,7 @@ impl<'tcx> TyCtxt<'tcx> { // Don't print the whole crate disambiguator. That's just // annoying in debug output. &(crate_disambiguator.to_fingerprint().to_hex())[..4], - self.def_path(def_id).to_string_no_crate() + self.def_path(def_id).to_string_no_crate_verbose() ) } diff --git a/compiler/rustc_middle/src/ty/query/profiling_support.rs b/compiler/rustc_middle/src/ty/query/profiling_support.rs index d1257a1c394..4e8db3194bd 100644 --- a/compiler/rustc_middle/src/ty/query/profiling_support.rs +++ b/compiler/rustc_middle/src/ty/query/profiling_support.rs @@ -7,7 +7,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, use rustc_hir::definitions::DefPathData; use rustc_query_system::query::QueryCache; use rustc_query_system::query::QueryState; -use rustc_span::symbol::Symbol; use std::fmt::Debug; use std::io::Write; @@ -56,18 +55,22 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { }; let dis_buffer = &mut [0u8; 16]; + let crate_name; + let other_name; let name; let dis; let end_index; match def_key.disambiguated_data.data { DefPathData::CrateRoot => { - name = self.tcx.original_crate_name(def_id.krate); + crate_name = self.tcx.original_crate_name(def_id.krate).as_str(); + name = &*crate_name; dis = ""; end_index = 3; } other => { - name = Symbol::intern(&other.to_string()); + other_name = other.to_string(); + name = other_name.as_str(); if def_key.disambiguated_data.disambiguator == 0 { dis = ""; end_index = 3; @@ -81,7 +84,6 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { } } - let name = &*name.as_str(); let components = [ StringComponent::Ref(parent_string_id), StringComponent::Value("::"), diff --git a/compiler/rustc_passes/src/hir_id_validator.rs b/compiler/rustc_passes/src/hir_id_validator.rs index 2edbc29b7ef..24695f5cdfa 100644 --- a/compiler/rustc_passes/src/hir_id_validator.rs +++ b/compiler/rustc_passes/src/hir_id_validator.rs @@ -112,14 +112,14 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> { missing_items.push(format!( "[local_id: {}, owner: {}]", local_id, - self.hir_map.def_path(owner).to_string_no_crate() + self.hir_map.def_path(owner).to_string_no_crate_verbose() )); } self.error(|| { format!( "ItemLocalIds not assigned densely in {}. \ Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}", - self.hir_map.def_path(owner).to_string_no_crate(), + self.hir_map.def_path(owner).to_string_no_crate_verbose(), max, missing_items, self.hir_ids_seen @@ -148,8 +148,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { format!( "HirIdValidator: The recorded owner of {} is {} instead of {}", self.hir_map.node_to_string(hir_id), - self.hir_map.def_path(hir_id.owner).to_string_no_crate(), - self.hir_map.def_path(owner).to_string_no_crate() + self.hir_map.def_path(hir_id.owner).to_string_no_crate_verbose(), + self.hir_map.def_path(owner).to_string_no_crate_verbose() ) }); } -- cgit 1.4.1-3-g733a5