Skip to content

Commit 6f427b3

Browse files
committed
Use join_path_syms in one more place.
This one is a bit marginal, because the segments are a mix of symbols and strings.
1 parent 5bfb50b commit 6f427b3

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,32 +181,26 @@ pub struct DisambiguatedDefPathData {
181181
}
182182

183183
impl DisambiguatedDefPathData {
184-
pub fn fmt_maybe_verbose(&self, writer: &mut impl Write, verbose: bool) -> fmt::Result {
184+
pub fn as_sym(&self, verbose: bool) -> Symbol {
185185
match self.data.name() {
186186
DefPathDataName::Named(name) => {
187187
if verbose && self.disambiguator != 0 {
188-
write!(writer, "{}#{}", name, self.disambiguator)
188+
Symbol::intern(&format!("{}#{}", name, self.disambiguator))
189189
} else {
190-
writer.write_str(name.as_str())
190+
name
191191
}
192192
}
193193
DefPathDataName::Anon { namespace } => {
194194
if let DefPathData::AnonAssocTy(method) = self.data {
195-
write!(writer, "{}::{{{}#{}}}", method, namespace, self.disambiguator)
195+
Symbol::intern(&format!("{}::{{{}#{}}}", method, namespace, self.disambiguator))
196196
} else {
197-
write!(writer, "{{{}#{}}}", namespace, self.disambiguator)
197+
Symbol::intern(&format!("{{{}#{}}}", namespace, self.disambiguator))
198198
}
199199
}
200200
}
201201
}
202202
}
203203

204-
impl fmt::Display for DisambiguatedDefPathData {
205-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
206-
self.fmt_maybe_verbose(f, true)
207-
}
208-
}
209-
210204
#[derive(Clone, Debug, Encodable, Decodable)]
211205
pub struct DefPath {
212206
/// The path leading from the crate root to the item.
@@ -250,7 +244,7 @@ impl DefPath {
250244
let mut s = String::with_capacity(self.data.len() * 16);
251245

252246
for component in &self.data {
253-
write!(s, "::{component}").unwrap();
247+
write!(s, "::{}", component.as_sym(true)).unwrap();
254248
}
255249

256250
s
@@ -266,7 +260,7 @@ impl DefPath {
266260
for component in &self.data {
267261
s.extend(opt_delimiter);
268262
opt_delimiter = Some('-');
269-
write!(s, "{component}").unwrap();
263+
write!(s, "{}", component.as_sym(true)).unwrap();
270264
}
271265

272266
s

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
24302430
}
24312431

24322432
let verbose = self.should_print_verbose();
2433-
disambiguated_data.fmt_maybe_verbose(self, verbose)?;
2433+
write!(self, "{}", disambiguated_data.as_sym(verbose))?;
24342434

24352435
self.empty_path = false;
24362436

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use std::path::PathBuf;
5151
use std::{cmp, fmt, iter};
5252

5353
use rustc_abi::ExternAbi;
54+
use rustc_ast::join_path_syms;
5455
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
5556
use rustc_errors::{
5657
Applicability, Diag, DiagStyledString, IntoDiagArg, MultiSpan, StringPart, pluralize,
@@ -73,7 +74,7 @@ use rustc_middle::ty::{
7374
TypeVisitableExt,
7475
};
7576
use rustc_span::def_id::LOCAL_CRATE;
76-
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Pos, Span, sym};
77+
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Pos, Span, Symbol, sym};
7778
use tracing::{debug, instrument};
7879

7980
use crate::error_reporting::TypeErrCtxt;
@@ -225,7 +226,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
225226

226227
struct AbsolutePathPrinter<'tcx> {
227228
tcx: TyCtxt<'tcx>,
228-
segments: Vec<String>,
229+
segments: Vec<Symbol>,
229230
}
230231

231232
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
@@ -253,7 +254,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
253254
}
254255

255256
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
256-
self.segments = vec![self.tcx.crate_name(cnum).to_string()];
257+
self.segments = vec![self.tcx.crate_name(cnum)];
257258
Ok(())
258259
}
259260
fn path_qualified(
@@ -279,7 +280,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
279280
disambiguated_data: &DisambiguatedDefPathData,
280281
) -> Result<(), PrintError> {
281282
print_prefix(self)?;
282-
self.segments.push(disambiguated_data.to_string());
283+
self.segments.push(disambiguated_data.as_sym(true));
283284
Ok(())
284285
}
285286
fn path_generic_args(
@@ -314,7 +315,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
314315
// known" by the same name, we use the "absolute path" which uses the original
315316
// crate name instead.
316317
let (expected, found) = if expected_str == found_str {
317-
(expected_abs.join("::"), found_abs.join("::"))
318+
(join_path_syms(&expected_abs), join_path_syms(&found_abs))
318319
} else {
319320
(expected_str.clone(), found_str.clone())
320321
};

0 commit comments

Comments
 (0)