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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 10 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)