Skip to content

Commit f8edb84

Browse files
committed
Replace Symbol::intern calls with preinterned symbols
1 parent e4190a7 commit f8edb84

File tree

13 files changed

+34
-26
lines changed

13 files changed

+34
-26
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_ast::{NodeId, PatKind, attr, token};
44
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};
55
use rustc_session::Session;
66
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
7+
use rustc_span::Span;
78
use rustc_span::source_map::Spanned;
89
use rustc_span::symbol::sym;
9-
use rustc_span::{Span, Symbol};
1010
use rustc_target::spec::abi;
1111
use thin_vec::ThinVec;
1212

@@ -692,7 +692,7 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
692692
{
693693
sess.dcx().emit_err(errors::IncompatibleFeatures {
694694
spans: vec![gce_span],
695-
f1: Symbol::intern("-Znext-solver=globally"),
695+
f1: sym::dash_z_next_dash_solver_equals_globally,
696696
f2: sym::generic_const_exprs,
697697
});
698698
}

compiler/rustc_borrowck/src/universal_regions.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use rustc_middle::ty::{
3333
TyCtxt, TypeVisitableExt,
3434
};
3535
use rustc_middle::{bug, span_bug};
36+
use rustc_span::ErrorGuaranteed;
3637
use rustc_span::symbol::{kw, sym};
37-
use rustc_span::{ErrorGuaranteed, Symbol};
3838
use tracing::{debug, instrument};
3939

4040
use crate::BorrowckInferCtxt;
@@ -524,7 +524,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
524524

525525
let reg_vid = self
526526
.infcx
527-
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
527+
.next_nll_region_var(FR, || RegionCtxt::Free(sym::c_dash_variadic))
528528
.as_var();
529529

530530
let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
@@ -540,10 +540,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
540540
}
541541
}
542542

543-
let fr_fn_body = self
544-
.infcx
545-
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("fn_body")))
546-
.as_var();
543+
let fr_fn_body =
544+
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(sym::fn_body)).as_var();
547545

548546
let num_universals = self.infcx.num_region_vars();
549547

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
419419
if let Node::ConstBlock(_) = node {
420420
own_params.push(ty::GenericParamDef {
421421
index: next_index(),
422-
name: Symbol::intern("<const_ty>"),
422+
name: rustc_span::sym::lt_const_underscore_ty_rt,
423423
def_id: def_id.to_def_id(),
424424
pure_wrt_drop: false,
425425
kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false },

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
664664
let is_write = sugg_span.ctxt().outer_expn_data().macro_def_id.is_some_and(|def_id| {
665665
tcx.is_diagnostic_item(sym::write_macro, def_id)
666666
|| tcx.is_diagnostic_item(sym::writeln_macro, def_id)
667-
}) && item_name.name == Symbol::intern("write_fmt");
667+
}) && item_name.name == sym::write_fmt;
668668
let mut err = if is_write && let SelfSource::MethodCall(rcvr_expr) = source {
669669
self.suggest_missing_writer(rcvr_ty, rcvr_expr)
670670
} else {

compiler/rustc_lint/src/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ impl UnusedImportBraces {
15631563
}
15641564
rename.unwrap_or(orig_ident).name
15651565
}
1566-
ast::UseTreeKind::Glob => Symbol::intern("*"),
1566+
ast::UseTreeKind::Glob => sym::asterisk,
15671567
ast::UseTreeKind::Nested { .. } => return,
15681568
};
15691569

compiler/rustc_metadata/src/creader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
862862
// and see what's a global allocator, including if we ourselves are a
863863
// global allocator.
864864
let mut global_allocator =
865-
self.cstore.has_global_allocator.then(|| Symbol::intern("this crate"));
865+
self.cstore.has_global_allocator.then_some(sym::this_space_crate);
866866
for (_, data) in self.cstore.iter_crate_data() {
867867
if data.has_global_allocator() {
868868
match global_allocator {
@@ -877,7 +877,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
877877
}
878878
}
879879
let mut alloc_error_handler =
880-
self.cstore.has_alloc_error_handler.then(|| Symbol::intern("this crate"));
880+
self.cstore.has_alloc_error_handler.then_some(sym::this_space_crate);
881881
for (_, data) in self.cstore.iter_crate_data() {
882882
if data.has_alloc_error_handler() {
883883
match alloc_error_handler {

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,9 @@ impl MetadataBlob {
875875
let def_name = if item == CRATE_DEF_INDEX {
876876
rustc_span::symbol::kw::Crate
877877
} else {
878-
def_key
879-
.disambiguated_data
880-
.data
881-
.get_opt_name()
882-
.unwrap_or_else(|| Symbol::intern("???"))
878+
def_key.disambiguated_data.data.get_opt_name().unwrap_or(
879+
rustc_span::sym::question_mark_question_mark_question_mark,
880+
)
883881
};
884882
let visibility =
885883
root.tables.visibility.get(blob, item).unwrap().decode(blob).map_id(

compiler/rustc_parse/src/parser/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::{
99
};
1010
use rustc_errors::{Applicability, PResult};
1111
use rustc_span::symbol::{Ident, kw, sym};
12-
use rustc_span::{ErrorGuaranteed, Span, Symbol};
12+
use rustc_span::{ErrorGuaranteed, Span};
1313
use thin_vec::{ThinVec, thin_vec};
1414

1515
use super::{Parser, PathStyle, SeqSep, TokenType, Trailing};
@@ -1139,7 +1139,7 @@ impl<'a> Parser<'a> {
11391139
Some(ast::Path {
11401140
span: fn_token_span.to(self.prev_token.span),
11411141
segments: thin_vec![ast::PathSegment {
1142-
ident: Ident::new(Symbol::intern("Fn"), fn_token_span),
1142+
ident: Ident::new(sym::Fn, fn_token_span),
11431143
id: DUMMY_NODE_ID,
11441144
args: Some(P(ast::GenericArgs::Parenthesized(ast::ParenthesizedArgs {
11451145
span: args_lo.to(self.prev_token.span),

compiler/rustc_resolve/src/late/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3114,9 +3114,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
31143114
}
31153115

31163116
let existing_name = match &in_scope_lifetimes[..] {
3117-
[] => Symbol::intern("'a"),
3117+
[] => sym::apostrophe_a,
31183118
[(existing, _)] => existing.name,
3119-
_ => Symbol::intern("'lifetime"),
3119+
_ => sym::apostrophe_lifetime,
31203120
};
31213121

31223122
let mut spans_suggs: Vec<_> = Vec::new();

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ fn module_to_string(module: Module<'_>) -> Option<String> {
22702270
collect_mod(names, parent);
22712271
}
22722272
} else {
2273-
names.push(Symbol::intern("<opaque>"));
2273+
names.push(sym::lt_opaque_gt);
22742274
collect_mod(names, module.parent.unwrap());
22752275
}
22762276
}

compiler/rustc_session/src/output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute]) -> Symbol {
8787
}
8888
}
8989

90-
Symbol::intern("rust_out")
90+
sym::rust_out
9191
}
9292

9393
pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {

compiler/rustc_span/src/symbol.rs

+13
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ symbols! {
297297
Return,
298298
Right,
299299
Rust,
300+
RustaceansAreAwesome,
300301
RustcDecodable,
301302
RustcEncodable,
302303
RwLock,
@@ -401,6 +402,8 @@ symbols! {
401402
anon_adt,
402403
anonymous_lifetime_in_impl_trait,
403404
any,
405+
apostrophe_a: "'a",
406+
apostrophe_lifetime: "'lifetime",
404407
append_const_msg,
405408
arbitrary_enum_discriminant,
406409
arbitrary_self_types,
@@ -439,6 +442,7 @@ symbols! {
439442
associated_types,
440443
assume,
441444
assume_init,
445+
asterisk: "*",
442446
async_await,
443447
async_call,
444448
async_call_mut,
@@ -519,6 +523,7 @@ symbols! {
519523
btreeset_iter,
520524
builtin_syntax,
521525
c,
526+
c_dash_variadic,
522527
c_str,
523528
c_str_literals,
524529
c_unwind,
@@ -703,6 +708,7 @@ symbols! {
703708
custom_test_frameworks,
704709
d,
705710
d32,
711+
dash_z_next_dash_solver_equals_globally: "-Znext-solver=globally",
706712
dbg_macro,
707713
dead_code,
708714
dealloc,
@@ -921,6 +927,7 @@ symbols! {
921927
fmuladdf32,
922928
fmuladdf64,
923929
fn_align,
930+
fn_body,
924931
fn_delegation,
925932
fn_must_use,
926933
fn_mut,
@@ -1176,6 +1183,8 @@ symbols! {
11761183
loongarch_target_feature,
11771184
loop_break_value,
11781185
lt,
1186+
lt_const_underscore_ty_rt: "<const_ty>",
1187+
lt_opaque_gt: "<opaque>",
11791188
macro_at_most_once_rep,
11801189
macro_attributes_in_derive_output,
11811190
macro_escape,
@@ -1558,6 +1567,7 @@ symbols! {
15581567
qreg_low8,
15591568
quad_precision_float,
15601569
question_mark,
1570+
question_mark_question_mark_question_mark: "???",
15611571
quote,
15621572
range_inclusive_new,
15631573
raw_dylib,
@@ -1652,6 +1662,7 @@ symbols! {
16521662
rust_eh_catch_typeinfo,
16531663
rust_eh_personality,
16541664
rust_logo,
1665+
rust_out,
16551666
rustc,
16561667
rustc_abi,
16571668
rustc_allocator,
@@ -1966,6 +1977,7 @@ symbols! {
19661977
test_removed_feature,
19671978
test_runner,
19681979
test_unstable_lint,
1980+
this_space_crate: "this crate",
19691981
thread,
19701982
thread_local,
19711983
thread_local_macro,
@@ -2173,6 +2185,7 @@ symbols! {
21732185
wrapping_sub,
21742186
wreg,
21752187
write_bytes,
2188+
write_fmt,
21762189
write_macro,
21772190
write_str,
21782191
write_via_move,

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_middle::ty::{
1818
TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
1919
};
2020
use rustc_span::Span;
21-
use rustc_span::symbol::Symbol;
2221
use smallvec::SmallVec;
2322
use tracing::{debug, instrument};
2423

@@ -679,7 +678,7 @@ fn receiver_is_dispatchable<'tcx>(
679678
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
680679
// replace this with `dyn Trait`
681680
let unsized_self_ty: Ty<'tcx> =
682-
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
681+
Ty::new_param(tcx, u32::MAX, rustc_span::sym::RustaceansAreAwesome);
683682

684683
// `Receiver[Self => U]`
685684
let unsized_receiver_ty =

0 commit comments

Comments
 (0)