Skip to content

Commit 6537d39

Browse files
committed
Revert "Rollup merge of rust-lang#99342 - TaKO8Ki:avoid-symbol-to-string-conversions, r=compiler-errors"
This reverts commit 6277ac2, reversing changes made to 0c6e01b.
1 parent 1cd72b7 commit 6537d39

File tree

18 files changed

+59
-50
lines changed

18 files changed

+59
-50
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::ty::{
2323
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2424
use rustc_span::hygiene::DesugaringKind;
2525
use rustc_span::symbol::sym;
26-
use rustc_span::{BytePos, Span, Symbol};
26+
use rustc_span::{BytePos, Span};
2727
use rustc_trait_selection::infer::InferCtxtExt;
2828
use rustc_trait_selection::traits::TraitEngineExt as _;
2929

@@ -1227,7 +1227,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12271227
from_closure: false,
12281228
region_name:
12291229
RegionName {
1230-
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
1230+
source:
1231+
RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name),
12311232
..
12321233
},
12331234
span,
@@ -1761,7 +1762,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17611762
borrow_span: Span,
17621763
name: &Option<String>,
17631764
upvar_span: Span,
1764-
upvar_name: Symbol,
1765+
upvar_name: &str,
17651766
escape_span: Span,
17661767
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
17671768
let tcx = self.infcx.tcx;

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::mir::{
1212
};
1313
use rustc_middle::ty::adjustment::PointerCast;
1414
use rustc_middle::ty::{self, RegionVid, TyCtxt};
15-
use rustc_span::symbol::{kw, Symbol};
15+
use rustc_span::symbol::Symbol;
1616
use rustc_span::{sym, DesugaringKind, Span};
1717

1818
use crate::region_infer::BlameConstraint;
@@ -282,7 +282,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
282282
) {
283283
if let ConstraintCategory::OpaqueType = category {
284284
let suggestable_name =
285-
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
285+
if region_name.was_named() { region_name.to_string() } else { "'_".to_string() };
286286

287287
let msg = format!(
288288
"you can add a bound to the {}to make it last less than `'static` and match `{}`",

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use rustc_middle::ty::subst::InternalSubsts;
1919
use rustc_middle::ty::Region;
2020
use rustc_middle::ty::TypeVisitor;
2121
use rustc_middle::ty::{self, RegionVid, Ty};
22-
use rustc_span::symbol::{kw, sym, Ident};
22+
use rustc_span::symbol::sym;
23+
use rustc_span::symbol::Ident;
2324
use rustc_span::Span;
2425

2526
use crate::borrowck_errors;
@@ -757,7 +758,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
757758
return;
758759
};
759760

760-
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };
761+
let lifetime = if f.has_name() { fr_name.to_string() } else { "'_".to_string() };
761762

762763
let arg = match param.param.pat.simple_ident() {
763764
Some(simple_ident) => format!("argument `{}`", simple_ident),
@@ -769,7 +770,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
769770
self.infcx.tcx,
770771
diag,
771772
fn_returns,
772-
lifetime.to_string(),
773+
lifetime,
773774
Some(arg),
774775
captures,
775776
Some((param.param_ty_span, param.param_ty.to_string())),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ pub(crate) enum RegionNameSource {
3434
/// The `'static` region.
3535
Static,
3636
/// The free region corresponding to the environment of a closure.
37-
SynthesizedFreeEnvRegion(Span, &'static str),
37+
SynthesizedFreeEnvRegion(Span, String),
3838
/// The region corresponding to an argument.
3939
AnonRegionFromArgument(RegionNameHighlight),
4040
/// The region corresponding to a closure upvar.
41-
AnonRegionFromUpvar(Span, Symbol),
41+
AnonRegionFromUpvar(Span, String),
4242
/// The region corresponding to the return type of a closure.
43-
AnonRegionFromOutput(RegionNameHighlight, &'static str),
43+
AnonRegionFromOutput(RegionNameHighlight, String),
4444
/// The region from a type yielded by a generator.
4545
AnonRegionFromYieldTy(Span, String),
4646
/// An anonymous region from an async fn.
@@ -110,7 +110,7 @@ impl RegionName {
110110
}
111111
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
112112
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
113-
diag.note(*note);
113+
diag.note(note);
114114
}
115115
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
116116
span,
@@ -350,7 +350,10 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
350350

351351
Some(RegionName {
352352
name: region_name,
353-
source: RegionNameSource::SynthesizedFreeEnvRegion(fn_decl_span, note),
353+
source: RegionNameSource::SynthesizedFreeEnvRegion(
354+
fn_decl_span,
355+
note.to_string(),
356+
),
354357
})
355358
}
356359

@@ -675,7 +678,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
675678

676679
Some(RegionName {
677680
name: region_name,
678-
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
681+
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name.to_string()),
679682
})
680683
}
681684

@@ -753,7 +756,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
753756

754757
Some(RegionName {
755758
name: self.synthesize_region_name(),
756-
source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description),
759+
source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description.to_string()),
757760
})
758761
}
759762

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl Diagnostic {
453453
self
454454
}
455455

456-
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
456+
pub fn note_trait_signature(&mut self, name: String, signature: String) -> &mut Self {
457457
self.highlighted_note(vec![
458458
(format!("`{}` from trait: `", name), Style::NoStyle),
459459
(signature, Style::Highlight),

compiler/rustc_expand/src/module.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ pub fn default_submod_path<'a>(
218218
""
219219
};
220220

221-
let default_path_str = format!("{}{}.rs", relative_prefix, ident.name);
221+
let mod_name = ident.name.to_string();
222+
let default_path_str = format!("{}{}.rs", relative_prefix, mod_name);
222223
let secondary_path_str =
223-
format!("{}{}{}mod.rs", relative_prefix, ident.name, path::MAIN_SEPARATOR);
224+
format!("{}{}{}mod.rs", relative_prefix, mod_name, path::MAIN_SEPARATOR);
224225
let default_path = dir_path.join(&default_path_str);
225226
let secondary_path = dir_path.join(&secondary_path_str);
226227
let default_exists = sess.source_map().file_exists(&default_path);

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'_, 'tcx>, ns: Namespace) -> FmtPr
138138
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) =
139139
infcx.inner.borrow_mut().type_variables().var_origin(ty_vid).kind
140140
{
141-
Some(name)
141+
Some(name.to_string())
142142
} else {
143143
None
144144
}
@@ -151,7 +151,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'_, 'tcx>, ns: Namespace) -> FmtPr
151151
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) =
152152
infcx.inner.borrow_mut().const_unification_table().probe_value(ct_vid).origin.kind
153153
{
154-
return Some(name);
154+
return Some(name.to_string());
155155
} else {
156156
None
157157
}

compiler/rustc_middle/src/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
19751975
min_size = field_end;
19761976
}
19771977
FieldInfo {
1978-
name,
1978+
name: name.to_string(),
19791979
offset: offset.bytes(),
19801980
size: field_layout.size.bytes(),
19811981
align: field_layout.align.abi.bytes(),
@@ -1984,7 +1984,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
19841984
.collect();
19851985

19861986
VariantInfo {
1987-
name: n,
1987+
name: n.map(|n| n.to_string()),
19881988
kind: if layout.is_unsized() { SizeKind::Min } else { SizeKind::Exact },
19891989
align: layout.align.abi.bytes(),
19901990
size: if min_size.bytes() == 0 { layout.size.bytes() } else { min_size.bytes() },

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,11 @@ pub trait PrettyPrinter<'tcx>:
10301030
}
10311031
}
10321032

1033-
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
1033+
fn ty_infer_name(&self, _: ty::TyVid) -> Option<String> {
10341034
None
10351035
}
10361036

1037-
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<Symbol> {
1037+
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<String> {
10381038
None
10391039
}
10401040

@@ -1550,8 +1550,8 @@ pub struct FmtPrinterData<'a, 'tcx> {
15501550

15511551
pub region_highlight_mode: RegionHighlightMode<'tcx>,
15521552

1553-
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<Symbol> + 'a>>,
1554-
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<Symbol> + 'a>>,
1553+
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<String> + 'a>>,
1554+
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<String> + 'a>>,
15551555
}
15561556

15571557
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
@@ -1841,11 +1841,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
18411841
}
18421842

18431843
impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
1844-
fn ty_infer_name(&self, id: ty::TyVid) -> Option<Symbol> {
1844+
fn ty_infer_name(&self, id: ty::TyVid) -> Option<String> {
18451845
self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id))
18461846
}
18471847

1848-
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
1848+
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<String> {
18491849
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
18501850
}
18511851

compiler/rustc_session/src/code_stats.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use rustc_data_structures::fx::FxHashSet;
22
use rustc_data_structures::sync::Lock;
3-
use rustc_span::Symbol;
43
use rustc_target::abi::{Align, Size};
54
use std::cmp::{self, Ordering};
65

76
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
87
pub struct VariantInfo {
9-
pub name: Option<Symbol>,
8+
pub name: Option<String>,
109
pub kind: SizeKind,
1110
pub size: u64,
1211
pub align: u64,
@@ -21,7 +20,7 @@ pub enum SizeKind {
2120

2221
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
2322
pub struct FieldInfo {
24-
pub name: Symbol,
23+
pub name: String,
2524
pub offset: u64,
2625
pub size: u64,
2726
pub align: u64,
@@ -120,7 +119,7 @@ impl CodeStats {
120119
let VariantInfo { ref name, kind: _, align: _, size, ref fields } = *variant_info;
121120
let indent = if !struct_like {
122121
let name = match name.as_ref() {
123-
Some(name) => name.to_string(),
122+
Some(name) => name.to_owned(),
124123
None => i.to_string(),
125124
};
126125
println!(

compiler/rustc_typeck/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24862486
concrete type's name `{type_name}` instead if you want to \
24872487
specify its type parameters"
24882488
),
2489-
type_name,
2489+
type_name.to_string(),
24902490
Applicability::MaybeIncorrect,
24912491
);
24922492
}

compiler/rustc_typeck/src/check/compare_method.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ fn compare_self_type<'tcx>(
544544
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
545545
err.span_label(span, format!("trait method declared without `{self_descr}`"));
546546
} else {
547-
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
547+
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
548548
}
549549
let reported = err.emit();
550550
return Err(reported);
@@ -564,7 +564,7 @@ fn compare_self_type<'tcx>(
564564
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
565565
err.span_label(span, format!("`{self_descr}` used in trait"));
566566
} else {
567-
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
567+
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
568568
}
569569
let reported = err.emit();
570570
return Err(reported);
@@ -803,7 +803,7 @@ fn compare_number_of_method_arguments<'tcx>(
803803
),
804804
);
805805
} else {
806-
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
806+
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
807807
}
808808
err.span_label(
809809
impl_span,

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18561856
let remaining_private_fields_len = remaining_private_fields.len();
18571857
let names = match &remaining_private_fields
18581858
.iter()
1859-
.map(|(name, _, _)| name)
1859+
.map(|(name, _, _)| name.to_string())
18601860
.collect::<Vec<_>>()[..]
18611861
{
18621862
_ if remaining_private_fields_len > 6 => String::new(),

compiler/rustc_typeck/src/check/method/suggest.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_middle::ty::print::with_crate_prefix;
1919
use rustc_middle::ty::ToPolyTraitRef;
2020
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeVisitable};
2121
use rustc_span::symbol::{kw, sym, Ident};
22-
use rustc_span::Symbol;
2322
use rustc_span::{lev_distance, source_map, ExpnKind, FileName, MacroKind, Span};
2423
use rustc_trait_selection::traits::error_reporting::on_unimplemented::InferCtxtExt as _;
2524
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -1549,7 +1548,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15491548
Option<ObligationCause<'tcx>>,
15501549
)],
15511550
) {
1552-
let mut derives = Vec::<(String, Span, Symbol)>::new();
1551+
let mut derives = Vec::<(String, Span, String)>::new();
15531552
let mut traits = Vec::<Span>::new();
15541553
for (pred, _, _) in unsatisfied_predicates {
15551554
let ty::PredicateKind::Trait(trait_pred) = pred.kind().skip_binder() else { continue };
@@ -1582,12 +1581,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15821581
derives.push((
15831582
self_name.clone(),
15841583
self_span,
1585-
parent_diagnostic_name,
1584+
parent_diagnostic_name.to_string(),
15861585
));
15871586
}
15881587
}
15891588
}
1590-
derives.push((self_name, self_span, diagnostic_name));
1589+
derives.push((self_name, self_span, diagnostic_name.to_string()));
15911590
} else {
15921591
traits.push(self.tcx.def_span(trait_pred.def_id()));
15931592
}
@@ -1610,7 +1609,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16101609
continue;
16111610
}
16121611
}
1613-
derives_grouped.push((self_name, self_span, trait_name.to_string()));
1612+
derives_grouped.push((self_name, self_span, trait_name));
16141613
}
16151614

16161615
let len = traits.len();

compiler/rustc_typeck/src/impl_wf_check.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::def::DefKind;
1717
use rustc_hir::def_id::LocalDefId;
1818
use rustc_middle::ty::query::Providers;
1919
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
20-
use rustc_span::{Span, Symbol};
20+
use rustc_span::Span;
2121

2222
use std::collections::hash_map::Entry::{Occupied, Vacant};
2323

@@ -123,7 +123,12 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
123123
ty::GenericParamDefKind::Type { .. } => {
124124
let param_ty = ty::ParamTy::for_def(param);
125125
if !input_parameters.contains(&cgp::Parameter::from(param_ty)) {
126-
report_unused_parameter(tcx, tcx.def_span(param.def_id), "type", param_ty.name);
126+
report_unused_parameter(
127+
tcx,
128+
tcx.def_span(param.def_id),
129+
"type",
130+
&param_ty.to_string(),
131+
);
127132
}
128133
}
129134
ty::GenericParamDefKind::Lifetime => {
@@ -135,7 +140,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
135140
tcx,
136141
tcx.def_span(param.def_id),
137142
"lifetime",
138-
param.name,
143+
&param.name.to_string(),
139144
);
140145
}
141146
}
@@ -146,7 +151,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
146151
tcx,
147152
tcx.def_span(param.def_id),
148153
"const",
149-
param_ct.name,
154+
&param_ct.to_string(),
150155
);
151156
}
152157
}
@@ -173,7 +178,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
173178
// used elsewhere are not projected back out.
174179
}
175180

176-
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol) {
181+
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) {
177182
let mut err = struct_span_err!(
178183
tcx.sess,
179184
span,

0 commit comments

Comments
 (0)