Skip to content

Commit 71b698c

Browse files
committed
Replace Symbol::intern calls with preinterned symbols
1 parent 72d2db7 commit 71b698c

File tree

15 files changed

+40
-35
lines changed

15 files changed

+40
-35
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+3-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;
8-
use rustc_span::symbol::sym;
9-
use rustc_span::{Span, Symbol};
9+
use rustc_span::symbol::{Symbol, sym};
1010
use rustc_target::spec::abi;
1111
use thin_vec::ThinVec;
1212

@@ -690,6 +690,7 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
690690
.find(|feat| feat.gate_name == sym::generic_const_exprs)
691691
.map(|feat| feat.attr_sp)
692692
{
693+
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
693694
sess.dcx().emit_err(errors::IncompatibleFeatures {
694695
spans: vec![gce_span],
695696
f1: Symbol::intern("-Znext-solver=globally"),

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_codegen_cranelift/src/driver/jit.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn create_jit_module(
7474
jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8);
7575
let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
7676

77-
let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, Symbol::intern("dummy_cgu_name"));
77+
let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, sym::dummy_cgu_name);
7878

7979
crate::allocator::codegen(tcx, &mut jit_module);
8080

@@ -276,12 +276,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
276276

277277
jit_module.module.prepare_for_function_redefine(func_id).unwrap();
278278

279-
let mut cx = crate::CodegenCx::new(
280-
tcx,
281-
jit_module.isa(),
282-
false,
283-
Symbol::intern("dummy_cgu_name"),
284-
);
279+
let mut cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, sym::dummy_cgu_name);
285280
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
286281

287282
assert!(cx.global_asm.is_empty());

compiler/rustc_codegen_cranelift/src/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,13 @@ impl CodegenBackend for CraneliftCodegenBackend {
189189
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
190190
if sess.target.arch == "x86_64" && sess.target.os != "none" {
191191
// x86_64 mandates SSE2 support
192-
vec![Symbol::intern("fxsr"), sym::sse, Symbol::intern("sse2")]
192+
vec![sym::fsxr, sym::sse, sym::sse2]
193193
} else if sess.target.arch == "aarch64" {
194194
match &*sess.target.os {
195195
"none" => vec![],
196196
// On macOS the aes, sha2 and sha3 features are enabled by default and ring
197197
// fails to compile on macOS when they are not present.
198-
"macos" => vec![
199-
sym::neon,
200-
Symbol::intern("aes"),
201-
Symbol::intern("sha2"),
202-
Symbol::intern("sha3"),
203-
],
198+
"macos" => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
204199
// AArch64 mandates Neon support
205200
_ => vec![sym::neon],
206201
}

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::const_ty_placeholder,
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

+5-4
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
861861
// First up we check for global allocators. Look at the crate graph here
862862
// and see what's a global allocator, including if we ourselves are a
863863
// global allocator.
864-
let mut global_allocator =
865-
self.cstore.has_global_allocator.then(|| Symbol::intern("this crate"));
864+
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
865+
let this_crate = Symbol::intern("this crate");
866+
867+
let mut global_allocator = self.cstore.has_global_allocator.then_some(this_crate);
866868
for (_, data) in self.cstore.iter_crate_data() {
867869
if data.has_global_allocator() {
868870
match global_allocator {
@@ -876,8 +878,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
876878
}
877879
}
878880
}
879-
let mut alloc_error_handler =
880-
self.cstore.has_alloc_error_handler.then(|| Symbol::intern("this crate"));
881+
let mut alloc_error_handler = self.cstore.has_alloc_error_handler.then_some(this_crate);
881882
for (_, data) in self.cstore.iter_crate_data() {
882883
if data.has_alloc_error_handler() {
883884
match alloc_error_handler {

compiler/rustc_metadata/src/rmeta/decoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ impl MetadataBlob {
872872

873873
let def_kind = root.tables.def_kind.get(blob, item).unwrap();
874874
let def_key = root.tables.def_keys.get(blob, item).unwrap().decode(blob);
875+
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
875876
let def_name = if item == CRATE_DEF_INDEX {
876877
rustc_span::symbol::kw::Crate
877878
} else {

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

+1
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
31133113
}
31143114
}
31153115

3116+
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
31163117
let existing_name = match &in_scope_lifetimes[..] {
31173118
[] => Symbol::intern("'a"),
31183119
[(existing, _)] => existing.name,

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::opaque_module_name_placeholder);
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

+14
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,
@@ -377,6 +378,7 @@ symbols! {
377378
adt_const_params,
378379
advanced_slice_patterns,
379380
adx_target_feature,
381+
aes,
380382
aggregate_raw_ptr,
381383
alias,
382384
align,
@@ -439,6 +441,7 @@ symbols! {
439441
associated_types,
440442
assume,
441443
assume_init,
444+
asterisk: "*",
442445
async_await,
443446
async_call,
444447
async_call_mut,
@@ -519,6 +522,7 @@ symbols! {
519522
btreeset_iter,
520523
builtin_syntax,
521524
c,
525+
c_dash_variadic,
522526
c_str,
523527
c_str_literals,
524528
c_unwind,
@@ -649,6 +653,7 @@ symbols! {
649653
const_trait_bound_opt_out,
650654
const_trait_impl,
651655
const_try,
656+
const_ty_placeholder: "<const_ty>",
652657
constant,
653658
constructor,
654659
convert_identity,
@@ -778,6 +783,7 @@ symbols! {
778783
drop_types_in_const,
779784
dropck_eyepatch,
780785
dropck_parametricity,
786+
dummy_cgu_name,
781787
dylib,
782788
dyn_compatible_for_dispatch,
783789
dyn_metadata,
@@ -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,
@@ -961,6 +968,7 @@ symbols! {
961968
fs_create_dir,
962969
fsub_algebraic,
963970
fsub_fast,
971+
fsxr,
964972
full,
965973
fundamental,
966974
fused_iterator,
@@ -1384,6 +1392,7 @@ symbols! {
13841392
on,
13851393
on_unimplemented,
13861394
opaque,
1395+
opaque_module_name_placeholder: "<opaque>",
13871396
open_options_new,
13881397
ops,
13891398
opt_out_copy,
@@ -1652,6 +1661,7 @@ symbols! {
16521661
rust_eh_catch_typeinfo,
16531662
rust_eh_personality,
16541663
rust_logo,
1664+
rust_out,
16551665
rustc,
16561666
rustc_abi,
16571667
rustc_allocator,
@@ -1774,6 +1784,8 @@ symbols! {
17741784
self_in_typedefs,
17751785
self_struct_ctor,
17761786
semitransparent,
1787+
sha2,
1788+
sha3,
17771789
sha512_sm_x86,
17781790
shadow_call_stack,
17791791
shallow,
@@ -1887,6 +1899,7 @@ symbols! {
18871899
sreg,
18881900
sreg_low16,
18891901
sse,
1902+
sse2,
18901903
sse4a_target_feature,
18911904
stable,
18921905
staged_api,
@@ -2173,6 +2186,7 @@ symbols! {
21732186
wrapping_sub,
21742187
wreg,
21752188
write_bytes,
2189+
write_fmt,
21762190
write_macro,
21772191
write_str,
21782192
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)