Skip to content

Commit 26451ef

Browse files
committed
Avoid unnecessary internings.
Most involving `Symbol::intern` on string literals.
1 parent 6c0ff3d commit 26451ef

File tree

31 files changed

+84
-106
lines changed

31 files changed

+84
-106
lines changed

src/librustc/hir/lowering.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,7 @@ impl<'a> LoweringContext<'a> {
11451145
let unstable_span = self.sess.source_map().mark_span_with_reason(
11461146
CompilerDesugaringKind::Async,
11471147
span,
1148-
Some(vec![
1149-
Symbol::intern("gen_future"),
1150-
].into()),
1148+
Some(vec![sym::gen_future].into()),
11511149
);
11521150
let gen_future = self.expr_std_path(
11531151
unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new());
@@ -4177,9 +4175,7 @@ impl<'a> LoweringContext<'a> {
41774175
let unstable_span = this.sess.source_map().mark_span_with_reason(
41784176
CompilerDesugaringKind::TryBlock,
41794177
body.span,
4180-
Some(vec![
4181-
Symbol::intern("try_trait"),
4182-
].into()),
4178+
Some(vec![sym::try_trait].into()),
41834179
);
41844180
let mut block = this.lower_block(body, true).into_inner();
41854181
let tail = block.expr.take().map_or_else(

src/librustc/middle/lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
210210
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
211211
attrs.iter().find_map(|attr| Some(match attr {
212212
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
213-
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span),
214-
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span),
213+
_ if attr.check_name(sym::panic_handler) => (sym::panic_impl, attr.span),
214+
_ if attr.check_name(sym::alloc_error_handler) => (sym::oom, attr.span),
215215
_ => return None,
216216
}))
217217
}

src/librustc/middle/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a, 'tcx> Index<'tcx> {
437437
reason: Some(Symbol::intern(reason)),
438438
issue: 27812,
439439
},
440-
feature: Symbol::intern("rustc_private"),
440+
feature: sym::rustc_private,
441441
rustc_depr: None,
442442
const_stability: None,
443443
promotable: false,
@@ -880,7 +880,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
880880
// FIXME: only remove `libc` when `stdbuild` is active.
881881
// FIXME: remove special casing for `test`.
882882
remaining_lib_features.remove(&Symbol::intern("libc"));
883-
remaining_lib_features.remove(&Symbol::intern("test"));
883+
remaining_lib_features.remove(&sym::test);
884884

885885
let check_features =
886886
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {

src/librustc/session/config.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::source_map::{FileName, FilePathMapping};
1919
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
2020
use syntax::parse::token;
2121
use syntax::parse;
22-
use syntax::symbol::Symbol;
22+
use syntax::symbol::{sym, Symbol};
2323
use syntax::feature_gate::UnstableFeatures;
2424
use errors::emitter::HumanReadableErrorType;
2525

@@ -1503,31 +1503,31 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
15031503
Some(Symbol::intern(vendor)),
15041504
));
15051505
if sess.target.target.options.has_elf_tls {
1506-
ret.insert((Symbol::intern("target_thread_local"), None));
1506+
ret.insert((sym::target_thread_local, None));
15071507
}
15081508
for &i in &[8, 16, 32, 64, 128] {
15091509
if i >= min_atomic_width && i <= max_atomic_width {
15101510
let s = i.to_string();
15111511
ret.insert((
1512-
Symbol::intern("target_has_atomic"),
1512+
sym::target_has_atomic,
15131513
Some(Symbol::intern(&s)),
15141514
));
15151515
if &s == wordsz {
15161516
ret.insert((
1517-
Symbol::intern("target_has_atomic"),
1517+
sym::target_has_atomic,
15181518
Some(Symbol::intern("ptr")),
15191519
));
15201520
}
15211521
}
15221522
}
15231523
if atomic_cas {
1524-
ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern("cas"))));
1524+
ret.insert((sym::target_has_atomic, Some(Symbol::intern("cas"))));
15251525
}
15261526
if sess.opts.debug_assertions {
15271527
ret.insert((Symbol::intern("debug_assertions"), None));
15281528
}
15291529
if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
1530-
ret.insert((Symbol::intern("proc_macro"), None));
1530+
ret.insert((sym::proc_macro, None));
15311531
}
15321532
ret
15331533
}
@@ -1547,7 +1547,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
15471547
let default_cfg = default_configuration(sess);
15481548
// If the user wants a test runner, then add the test cfg
15491549
if sess.opts.test {
1550-
user_cfg.insert((Symbol::intern("test"), None));
1550+
user_cfg.insert((sym::test, None));
15511551
}
15521552
user_cfg.extend(default_cfg.iter().cloned());
15531553
user_cfg
@@ -2702,7 +2702,7 @@ mod tests {
27022702
use std::path::PathBuf;
27032703
use super::{Externs, OutputType, OutputTypes};
27042704
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
2705-
use syntax::symbol::Symbol;
2705+
use syntax::symbol::sym;
27062706
use syntax::edition::{Edition, DEFAULT_EDITION};
27072707
use syntax;
27082708
use super::Options;
@@ -2744,15 +2744,14 @@ mod tests {
27442744
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
27452745
let sess = build_session(sessopts, None, registry);
27462746
let cfg = build_configuration(&sess, to_crate_config(cfg));
2747-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2747+
assert!(cfg.contains(&(sym::test, None)));
27482748
});
27492749
}
27502750

27512751
// When the user supplies --test and --cfg test, don't implicitly add
27522752
// another --cfg test
27532753
#[test]
27542754
fn test_switch_implies_cfg_test_unless_cfg_test() {
2755-
use syntax::symbol::sym;
27562755
syntax::with_default_globals(|| {
27572756
let matches = &match optgroups().parse(&["--test".to_string(),
27582757
"--cfg=test".to_string()]) {

src/librustc_allocator/expand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
9191
call_site: item.span, // use the call site of the static
9292
def_site: None,
9393
format: MacroAttribute(Symbol::intern(name)),
94-
allow_internal_unstable: Some(vec![
95-
Symbol::intern("rustc_attrs"),
96-
].into()),
94+
allow_internal_unstable: Some(vec![sym::rustc_attrs].into()),
9795
allow_internal_unsafe: false,
9896
local_inner_macros: false,
9997
edition: self.sess.edition,
@@ -223,7 +221,7 @@ impl AllocFnFactory<'_> {
223221
}
224222

225223
fn attrs(&self) -> Vec<Attribute> {
226-
let special = Symbol::intern("rustc_std_internal_symbol");
224+
let special = sym::rustc_std_internal_symbol;
227225
let special = self.cx.meta_word(self.span, special);
228226
vec![self.cx.attribute(self.span, special)]
229227
}

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn add_configuration(
6868
sess: &Session,
6969
codegen_backend: &dyn CodegenBackend,
7070
) {
71-
let tf = Symbol::intern("target_feature");
71+
let tf = sym::target_feature;
7272

7373
cfg.extend(
7474
codegen_backend

src/librustc_metadata/cstore_impl.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ impl cstore::CStore {
431431
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
432432
let ext = SyntaxExtension::ProcMacro {
433433
expander: Box::new(BangProcMacro { client }),
434-
allow_internal_unstable: Some(vec![
435-
Symbol::intern("proc_macro_def_site"),
436-
].into()),
434+
allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()),
437435
edition: data.root.edition,
438436
};
439437
return LoadedMacro::ProcMacro(Lrc::new(ext));

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49444944
// This is less than ideal, it will not suggest a return type span on any
49454945
// method called `main`, regardless of whether it is actually the entry point,
49464946
// but it will still present it as the reason for the expected type.
4947-
Some((decl, ident, ident.name != Symbol::intern("main")))
4947+
Some((decl, ident, ident.name != sym::main))
49484948
}),
49494949
Node::TraitItem(&hir::TraitItem {
49504950
ident, node: hir::TraitItemKind::Method(hir::MethodSig {

src/libsyntax/ext/derive.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
5858
call_site: span,
5959
def_site: None,
6060
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
61-
allow_internal_unstable: Some(vec![
62-
Symbol::intern("rustc_attrs"),
63-
Symbol::intern("structural_match"),
64-
].into()),
61+
allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()),
6562
allow_internal_unsafe: false,
6663
local_inner_macros: false,
6764
edition: cx.parse_sess.edition,
@@ -74,7 +71,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
7471
attrs.push(cx.attribute(span, meta));
7572
}
7673
if names.contains(&Symbol::intern("Copy")) {
77-
let meta = cx.meta_word(span, Symbol::intern("rustc_copy_clone_marker"));
74+
let meta = cx.meta_word(span, sym::rustc_copy_clone_marker);
7875
attrs.push(cx.attribute(span, meta));
7976
}
8077
});

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
938938
}
939939
BuiltinDerive(func) => {
940940
expn_info.allow_internal_unstable = Some(vec![
941-
Symbol::intern("rustc_attrs"),
941+
sym::rustc_attrs,
942942
Symbol::intern("derive_clone_copy"),
943943
Symbol::intern("derive_eq"),
944944
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub fn compile(
396396
future this will become a hard error. Please use `allow_internal_unstable(\
397397
foo, bar)` to only allow the `foo` and `bar` features",
398398
);
399-
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into()
399+
vec![sym::allow_internal_unstable_backcompat_hack].into()
400400
})
401401
);
402402
let allow_internal_unsafe = attr::contains_name(&def.attrs, sym::allow_internal_unsafe);

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5787,7 +5787,7 @@ impl<'a> Parser<'a> {
57875787
VisibilityKind::Inherited => {}
57885788
_ => {
57895789
let is_macro_rules: bool = match self.token {
5790-
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"),
5790+
token::Ident(sid, _) => sid.name == sym::macro_rules,
57915791
_ => false,
57925792
};
57935793
let mut err = if is_macro_rules {

src/libsyntax/std_inject.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ fn ignored_span(sp: Span, edition: Edition) -> Span {
2020
call_site: DUMMY_SP,
2121
def_site: None,
2222
format: MacroAttribute(Symbol::intern("std_inject")),
23-
allow_internal_unstable: Some(vec![
24-
Symbol::intern("prelude_import"),
25-
].into()),
23+
allow_internal_unstable: Some(vec![sym::prelude_import].into()),
2624
allow_internal_unsafe: false,
2725
local_inner_macros: false,
2826
edition,
@@ -98,7 +96,7 @@ pub fn maybe_inject_crates_ref(
9896
krate.module.items.insert(0, P(ast::Item {
9997
attrs: vec![ast::Attribute {
10098
style: ast::AttrStyle::Outer,
101-
path: ast::Path::from_ident(ast::Ident::new(Symbol::intern("prelude_import"), span)),
99+
path: ast::Path::from_ident(ast::Ident::new(sym::prelude_import, span)),
102100
tokens: TokenStream::empty(),
103101
id: attr::mk_attr_id(),
104102
is_sugared_doc: false,

src/libsyntax/test.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,8 @@ fn generate_test_harness(sess: &ParseSess,
283283
mark.set_expn_info(ExpnInfo {
284284
call_site: DUMMY_SP,
285285
def_site: None,
286-
format: MacroAttribute(Symbol::intern("test_case")),
287-
allow_internal_unstable: Some(vec![
288-
Symbol::intern("main"),
289-
Symbol::intern("test"),
290-
Symbol::intern("rustc_attrs"),
291-
].into()),
286+
format: MacroAttribute(sym::test_case),
287+
allow_internal_unstable: Some(vec![sym::main, sym::test, sym::rustc_attrs].into()),
292288
allow_internal_unsafe: false,
293289
local_inner_macros: false,
294290
edition: sess.edition,
@@ -347,14 +343,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
347343
let call_test_main = ecx.stmt_expr(call_test_main);
348344

349345
// #![main]
350-
let main_meta = ecx.meta_word(sp, Symbol::intern("main"));
346+
let main_meta = ecx.meta_word(sp, sym::main);
351347
let main_attr = ecx.attribute(sp, main_meta);
352348

353349
// extern crate test as test_gensym
354350
let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp,
355351
test_id,
356352
vec![],
357-
ast::ItemKind::ExternCrate(Some(Symbol::intern("test")))
353+
ast::ItemKind::ExternCrate(Some(sym::test))
358354
));
359355

360356
// pub fn main() { ... }

src/libsyntax_ext/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use syntax::ext::base::{self, *};
1111
use syntax::feature_gate;
1212
use syntax::parse::{self, token};
1313
use syntax::ptr::P;
14-
use syntax::symbol::{Symbol, sym};
14+
use syntax::symbol::{kw, sym, Symbol};
1515
use syntax::ast::AsmDialect;
1616
use syntax_pos::Span;
1717
use syntax::tokenstream;
@@ -93,7 +93,7 @@ fn parse_inline_asm<'a>(
9393
})
9494
.unwrap_or(tts.len());
9595
let mut p = cx.new_parser_from_tts(&tts[first_colon..]);
96-
let mut asm = Symbol::intern("");
96+
let mut asm = kw::Invalid;
9797
let mut asm_str_style = None;
9898
let mut outputs = Vec::new();
9999
let mut inputs = Vec::new();

src/libsyntax_ext/assert.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::parse::token::{self, Token};
88
use syntax::parse::parser::Parser;
99
use syntax::print::pprust;
1010
use syntax::ptr::P;
11-
use syntax::symbol::Symbol;
11+
use syntax::symbol::{sym, Symbol};
1212
use syntax::tokenstream::{TokenStream, TokenTree};
1313
use syntax_pos::{Span, DUMMY_SP};
1414

@@ -27,7 +27,7 @@ pub fn expand_assert<'cx>(
2727

2828
let sp = sp.apply_mark(cx.current_expansion.mark);
2929
let panic_call = Mac_ {
30-
path: Path::from_ident(Ident::new(Symbol::intern("panic"), sp)),
30+
path: Path::from_ident(Ident::new(sym::panic, sp)),
3131
tts: custom_message.unwrap_or_else(|| {
3232
TokenStream::from(TokenTree::Token(
3333
DUMMY_SP,

src/libsyntax_ext/deriving/clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::attr;
77
use syntax::ext::base::{Annotatable, ExtCtxt};
88
use syntax::ext::build::AstBuilder;
99
use syntax::ptr::P;
10-
use syntax::symbol::{Symbol, kw, sym};
10+
use syntax::symbol::{kw, sym};
1111
use syntax_pos::Span;
1212

1313
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
@@ -76,7 +76,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
7676
_ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"),
7777
}
7878

79-
let inline = cx.meta_word(span, Symbol::intern("inline"));
79+
let inline = cx.meta_word(span, sym::inline);
8080
let attrs = vec![cx.attribute(span, inline)];
8181
let trait_def = TraitDef {
8282
span,

src/libsyntax_ext/deriving/cmp/eq.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use syntax::ast::{self, Expr, MetaItem, GenericArg};
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9-
use syntax::symbol::Symbol;
9+
use syntax::symbol::sym;
1010
use syntax_pos::Span;
1111

1212
pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,
1515
item: &Annotatable,
1616
push: &mut dyn FnMut(Annotatable)) {
17-
let inline = cx.meta_word(span, Symbol::intern("inline"));
18-
let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden"));
19-
let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]);
17+
let inline = cx.meta_word(span, sym::inline);
18+
let hidden = cx.meta_list_item_word(span, sym::hidden);
19+
let doc = cx.meta_list(span, sym::doc, vec![hidden]);
2020
let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)];
2121
let trait_def = TraitDef {
2222
span,

src/libsyntax_ext/deriving/cmp/ord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use syntax::ast::{self, Expr, MetaItem};
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9-
use syntax::symbol::Symbol;
9+
use syntax::symbol::sym;
1010
use syntax_pos::Span;
1111

1212
pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,
1515
item: &Annotatable,
1616
push: &mut dyn FnMut(Annotatable)) {
17-
let inline = cx.meta_word(span, Symbol::intern("inline"));
17+
let inline = cx.meta_word(span, sym::inline);
1818
let attrs = vec![cx.attribute(span, inline)];
1919
let trait_def = TraitDef {
2020
span,

src/libsyntax_ext/deriving/cmp/partial_eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syntax::ast::{BinOpKind, Expr, MetaItem};
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9-
use syntax::symbol::Symbol;
9+
use syntax::symbol::sym;
1010
use syntax_pos::Span;
1111

1212
pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
@@ -62,7 +62,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
6262

6363
macro_rules! md {
6464
($name:expr, $f:ident) => { {
65-
let inline = cx.meta_word(span, Symbol::intern("inline"));
65+
let inline = cx.meta_word(span, sym::inline);
6666
let attrs = vec![cx.attribute(span, inline)];
6767
MethodDef {
6868
name: $name,

0 commit comments

Comments
 (0)