Skip to content

Commit 35bad3e

Browse files
committed
Address review comment
1 parent 601c284 commit 35bad3e

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::llvm;
88
use crate::llvm::debuginfo::DIScope;
99
use rustc_hir::def_id::DefId;
1010
use rustc_hir::definitions::DefPathData;
11-
use rustc_span::symbol::Symbol;
1211

1312
pub fn mangled_name_of_instance<'a, 'tcx>(
1413
cx: &CodegenCx<'a, 'tcx>,
@@ -28,11 +27,18 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
2827
.parent
2928
.map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
3029

30+
let crate_name_as_str;
31+
let name_to_string;
3132
let namespace_name = match def_key.disambiguated_data.data {
32-
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
33-
data => Symbol::intern(&data.to_string()),
33+
DefPathData::CrateRoot => {
34+
crate_name_as_str = cx.tcx.crate_name(def_id.krate).as_str();
35+
&*crate_name_as_str
36+
}
37+
data => {
38+
name_to_string = data.to_string();
39+
&*name_to_string
40+
}
3441
};
35-
let namespace_name = namespace_name.as_str();
3642

3743
let scope = unsafe {
3844
llvm::LLVMRustDIBuilderCreateNameSpace(

compiler/rustc_hir/src/definitions.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ impl DisambiguatedDefPathData {
162162
if Ident::with_dummy_span(name).is_raw_guess() {
163163
writer.write_str("r#")?;
164164
}
165-
if self.disambiguator == 0 || !verbose {
166-
writer.write_str(&name.as_str())
167-
} else {
165+
if verbose && self.disambiguator != 0 {
168166
write!(writer, "{}#{}", name, self.disambiguator)
167+
} else {
168+
writer.write_str(&name.as_str())
169169
}
170170
}
171171
DefPathDataName::Anon { namespace } => {
@@ -224,7 +224,7 @@ impl DefPath {
224224
/// Returns a string representation of the `DefPath` without
225225
/// the crate-prefix. This method is useful if you don't have
226226
/// a `TyCtxt` available.
227-
pub fn to_string_no_crate(&self) -> String {
227+
pub fn to_string_no_crate_verbose(&self) -> String {
228228
let mut s = String::with_capacity(self.data.len() * 16);
229229

230230
for component in &self.data {
@@ -466,6 +466,7 @@ impl fmt::Display for DefPathData {
466466
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
467467
match self.name() {
468468
DefPathDataName::Named(name) => f.write_str(&name.as_str()),
469+
// FIXME(#70334): this will generate legacy {{closure}}, {{impl}}, etc
469470
DefPathDataName::Anon { namespace } => write!(f, "{{{{{}}}}}", namespace),
470471
}
471472
}

compiler/rustc_middle/src/hir/map/collector.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
244244
if cfg!(debug_assertions) {
245245
if hir_id.owner != self.current_dep_node_owner {
246246
let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) {
247-
Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate(),
247+
Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate_verbose(),
248248
None => format!("{:?}", node),
249249
};
250250

@@ -254,9 +254,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
254254
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
255255
self.source_map.span_to_string(span),
256256
node_str,
257-
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(),
257+
self.definitions
258+
.def_path(self.current_dep_node_owner)
259+
.to_string_no_crate_verbose(),
258260
self.current_dep_node_owner,
259-
self.definitions.def_path(hir_id.owner).to_string_no_crate(),
261+
self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(),
260262
hir_id.owner,
261263
)
262264
}

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ impl<'tcx> TyCtxt<'tcx> {
12721272
// Don't print the whole crate disambiguator. That's just
12731273
// annoying in debug output.
12741274
&(crate_disambiguator.to_fingerprint().to_hex())[..4],
1275-
self.def_path(def_id).to_string_no_crate()
1275+
self.def_path(def_id).to_string_no_crate_verbose()
12761276
)
12771277
}
12781278

compiler/rustc_middle/src/ty/query/profiling_support.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX,
77
use rustc_hir::definitions::DefPathData;
88
use rustc_query_system::query::QueryCache;
99
use rustc_query_system::query::QueryState;
10-
use rustc_span::symbol::Symbol;
1110
use std::fmt::Debug;
1211
use std::io::Write;
1312

@@ -56,18 +55,22 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
5655
};
5756

5857
let dis_buffer = &mut [0u8; 16];
58+
let crate_name;
59+
let other_name;
5960
let name;
6061
let dis;
6162
let end_index;
6263

6364
match def_key.disambiguated_data.data {
6465
DefPathData::CrateRoot => {
65-
name = self.tcx.original_crate_name(def_id.krate);
66+
crate_name = self.tcx.original_crate_name(def_id.krate).as_str();
67+
name = &*crate_name;
6668
dis = "";
6769
end_index = 3;
6870
}
6971
other => {
70-
name = Symbol::intern(&other.to_string());
72+
other_name = other.to_string();
73+
name = other_name.as_str();
7174
if def_key.disambiguated_data.disambiguator == 0 {
7275
dis = "";
7376
end_index = 3;
@@ -81,7 +84,6 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
8184
}
8285
}
8386

84-
let name = &*name.as_str();
8587
let components = [
8688
StringComponent::Ref(parent_string_id),
8789
StringComponent::Value("::"),

compiler/rustc_passes/src/hir_id_validator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
112112
missing_items.push(format!(
113113
"[local_id: {}, owner: {}]",
114114
local_id,
115-
self.hir_map.def_path(owner).to_string_no_crate()
115+
self.hir_map.def_path(owner).to_string_no_crate_verbose()
116116
));
117117
}
118118
self.error(|| {
119119
format!(
120120
"ItemLocalIds not assigned densely in {}. \
121121
Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}",
122-
self.hir_map.def_path(owner).to_string_no_crate(),
122+
self.hir_map.def_path(owner).to_string_no_crate_verbose(),
123123
max,
124124
missing_items,
125125
self.hir_ids_seen
@@ -148,8 +148,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
148148
format!(
149149
"HirIdValidator: The recorded owner of {} is {} instead of {}",
150150
self.hir_map.node_to_string(hir_id),
151-
self.hir_map.def_path(hir_id.owner).to_string_no_crate(),
152-
self.hir_map.def_path(owner).to_string_no_crate()
151+
self.hir_map.def_path(hir_id.owner).to_string_no_crate_verbose(),
152+
self.hir_map.def_path(owner).to_string_no_crate_verbose()
153153
)
154154
});
155155
}

0 commit comments

Comments
 (0)