Avoid unnecessary internings.

Most involving `Symbol::intern` on string literals.
This commit is contained in:
Nicholas Nethercote 2019-05-22 12:42:23 +10:00
parent 6c0ff3dd97
commit 26451ef7b5
31 changed files with 84 additions and 106 deletions

View File

@ -1145,9 +1145,7 @@ impl<'a> LoweringContext<'a> {
let unstable_span = self.sess.source_map().mark_span_with_reason( let unstable_span = self.sess.source_map().mark_span_with_reason(
CompilerDesugaringKind::Async, CompilerDesugaringKind::Async,
span, span,
Some(vec![ Some(vec![sym::gen_future].into()),
Symbol::intern("gen_future"),
].into()),
); );
let gen_future = self.expr_std_path( let gen_future = self.expr_std_path(
unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new()); unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new());
@ -4177,9 +4175,7 @@ impl<'a> LoweringContext<'a> {
let unstable_span = this.sess.source_map().mark_span_with_reason( let unstable_span = this.sess.source_map().mark_span_with_reason(
CompilerDesugaringKind::TryBlock, CompilerDesugaringKind::TryBlock,
body.span, body.span,
Some(vec![ Some(vec![sym::try_trait].into()),
Symbol::intern("try_trait"),
].into()),
); );
let mut block = this.lower_block(body, true).into_inner(); let mut block = this.lower_block(body, true).into_inner();
let tail = block.expr.take().map_or_else( let tail = block.expr.take().map_or_else(

View File

@ -210,8 +210,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> { pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
attrs.iter().find_map(|attr| Some(match attr { attrs.iter().find_map(|attr| Some(match attr {
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span), _ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span), _ if attr.check_name(sym::panic_handler) => (sym::panic_impl, attr.span),
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span), _ if attr.check_name(sym::alloc_error_handler) => (sym::oom, attr.span),
_ => return None, _ => return None,
})) }))
} }

View File

@ -437,7 +437,7 @@ impl<'a, 'tcx> Index<'tcx> {
reason: Some(Symbol::intern(reason)), reason: Some(Symbol::intern(reason)),
issue: 27812, issue: 27812,
}, },
feature: Symbol::intern("rustc_private"), feature: sym::rustc_private,
rustc_depr: None, rustc_depr: None,
const_stability: None, const_stability: None,
promotable: false, promotable: false,
@ -880,7 +880,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
// FIXME: only remove `libc` when `stdbuild` is active. // FIXME: only remove `libc` when `stdbuild` is active.
// FIXME: remove special casing for `test`. // FIXME: remove special casing for `test`.
remaining_lib_features.remove(&Symbol::intern("libc")); remaining_lib_features.remove(&Symbol::intern("libc"));
remaining_lib_features.remove(&Symbol::intern("test")); remaining_lib_features.remove(&sym::test);
let check_features = let check_features =
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| { |remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {

View File

@ -19,7 +19,7 @@ use syntax::source_map::{FileName, FilePathMapping};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax::parse::token; use syntax::parse::token;
use syntax::parse; use syntax::parse;
use syntax::symbol::Symbol; use syntax::symbol::{sym, Symbol};
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
use errors::emitter::HumanReadableErrorType; use errors::emitter::HumanReadableErrorType;
@ -1503,31 +1503,31 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
Some(Symbol::intern(vendor)), Some(Symbol::intern(vendor)),
)); ));
if sess.target.target.options.has_elf_tls { if sess.target.target.options.has_elf_tls {
ret.insert((Symbol::intern("target_thread_local"), None)); ret.insert((sym::target_thread_local, None));
} }
for &i in &[8, 16, 32, 64, 128] { for &i in &[8, 16, 32, 64, 128] {
if i >= min_atomic_width && i <= max_atomic_width { if i >= min_atomic_width && i <= max_atomic_width {
let s = i.to_string(); let s = i.to_string();
ret.insert(( ret.insert((
Symbol::intern("target_has_atomic"), sym::target_has_atomic,
Some(Symbol::intern(&s)), Some(Symbol::intern(&s)),
)); ));
if &s == wordsz { if &s == wordsz {
ret.insert(( ret.insert((
Symbol::intern("target_has_atomic"), sym::target_has_atomic,
Some(Symbol::intern("ptr")), Some(Symbol::intern("ptr")),
)); ));
} }
} }
} }
if atomic_cas { if atomic_cas {
ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern("cas")))); ret.insert((sym::target_has_atomic, Some(Symbol::intern("cas"))));
} }
if sess.opts.debug_assertions { if sess.opts.debug_assertions {
ret.insert((Symbol::intern("debug_assertions"), None)); ret.insert((Symbol::intern("debug_assertions"), None));
} }
if sess.opts.crate_types.contains(&CrateType::ProcMacro) { if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
ret.insert((Symbol::intern("proc_macro"), None)); ret.insert((sym::proc_macro, None));
} }
ret ret
} }
@ -1547,7 +1547,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
let default_cfg = default_configuration(sess); let default_cfg = default_configuration(sess);
// If the user wants a test runner, then add the test cfg // If the user wants a test runner, then add the test cfg
if sess.opts.test { if sess.opts.test {
user_cfg.insert((Symbol::intern("test"), None)); user_cfg.insert((sym::test, None));
} }
user_cfg.extend(default_cfg.iter().cloned()); user_cfg.extend(default_cfg.iter().cloned());
user_cfg user_cfg
@ -2702,7 +2702,7 @@ mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use super::{Externs, OutputType, OutputTypes}; use super::{Externs, OutputType, OutputTypes};
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel}; use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax::edition::{Edition, DEFAULT_EDITION}; use syntax::edition::{Edition, DEFAULT_EDITION};
use syntax; use syntax;
use super::Options; use super::Options;
@ -2744,7 +2744,7 @@ mod tests {
let (sessopts, cfg) = build_session_options_and_crate_config(matches); let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry); let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, to_crate_config(cfg)); let cfg = build_configuration(&sess, to_crate_config(cfg));
assert!(cfg.contains(&(Symbol::intern("test"), None))); assert!(cfg.contains(&(sym::test, None)));
}); });
} }
@ -2752,7 +2752,6 @@ mod tests {
// another --cfg test // another --cfg test
#[test] #[test]
fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
use syntax::symbol::sym;
syntax::with_default_globals(|| { syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string(), let matches = &match optgroups().parse(&["--test".to_string(),
"--cfg=test".to_string()]) { "--cfg=test".to_string()]) {

View File

@ -91,9 +91,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
call_site: item.span, // use the call site of the static call_site: item.span, // use the call site of the static
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern(name)), format: MacroAttribute(Symbol::intern(name)),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::rustc_attrs].into()),
Symbol::intern("rustc_attrs"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition: self.sess.edition, edition: self.sess.edition,
@ -223,7 +221,7 @@ impl AllocFnFactory<'_> {
} }
fn attrs(&self) -> Vec<Attribute> { fn attrs(&self) -> Vec<Attribute> {
let special = Symbol::intern("rustc_std_internal_symbol"); let special = sym::rustc_std_internal_symbol;
let special = self.cx.meta_word(self.span, special); let special = self.cx.meta_word(self.span, special);
vec![self.cx.attribute(self.span, special)] vec![self.cx.attribute(self.span, special)]
} }

View File

@ -68,7 +68,7 @@ pub fn add_configuration(
sess: &Session, sess: &Session,
codegen_backend: &dyn CodegenBackend, codegen_backend: &dyn CodegenBackend,
) { ) {
let tf = Symbol::intern("target_feature"); let tf = sym::target_feature;
cfg.extend( cfg.extend(
codegen_backend codegen_backend

View File

@ -431,9 +431,7 @@ impl cstore::CStore {
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote); let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let ext = SyntaxExtension::ProcMacro { let ext = SyntaxExtension::ProcMacro {
expander: Box::new(BangProcMacro { client }), expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()),
Symbol::intern("proc_macro_def_site"),
].into()),
edition: data.root.edition, edition: data.root.edition,
}; };
return LoadedMacro::ProcMacro(Lrc::new(ext)); return LoadedMacro::ProcMacro(Lrc::new(ext));

View File

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

View File

@ -58,10 +58,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
call_site: span, call_site: span,
def_site: None, def_site: None,
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()),
Symbol::intern("rustc_attrs"),
Symbol::intern("structural_match"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition: cx.parse_sess.edition, edition: cx.parse_sess.edition,
@ -74,7 +71,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
attrs.push(cx.attribute(span, meta)); attrs.push(cx.attribute(span, meta));
} }
if names.contains(&Symbol::intern("Copy")) { if names.contains(&Symbol::intern("Copy")) {
let meta = cx.meta_word(span, Symbol::intern("rustc_copy_clone_marker")); let meta = cx.meta_word(span, sym::rustc_copy_clone_marker);
attrs.push(cx.attribute(span, meta)); attrs.push(cx.attribute(span, meta));
} }
}); });

View File

@ -938,7 +938,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
} }
BuiltinDerive(func) => { BuiltinDerive(func) => {
expn_info.allow_internal_unstable = Some(vec![ expn_info.allow_internal_unstable = Some(vec![
Symbol::intern("rustc_attrs"), sym::rustc_attrs,
Symbol::intern("derive_clone_copy"), Symbol::intern("derive_clone_copy"),
Symbol::intern("derive_eq"), Symbol::intern("derive_eq"),
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize

View File

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

View File

@ -5787,7 +5787,7 @@ impl<'a> Parser<'a> {
VisibilityKind::Inherited => {} VisibilityKind::Inherited => {}
_ => { _ => {
let is_macro_rules: bool = match self.token { let is_macro_rules: bool = match self.token {
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"), token::Ident(sid, _) => sid.name == sym::macro_rules,
_ => false, _ => false,
}; };
let mut err = if is_macro_rules { let mut err = if is_macro_rules {

View File

@ -20,9 +20,7 @@ fn ignored_span(sp: Span, edition: Edition) -> Span {
call_site: DUMMY_SP, call_site: DUMMY_SP,
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern("std_inject")), format: MacroAttribute(Symbol::intern("std_inject")),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::prelude_import].into()),
Symbol::intern("prelude_import"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition, edition,
@ -98,7 +96,7 @@ pub fn maybe_inject_crates_ref(
krate.module.items.insert(0, P(ast::Item { krate.module.items.insert(0, P(ast::Item {
attrs: vec![ast::Attribute { attrs: vec![ast::Attribute {
style: ast::AttrStyle::Outer, style: ast::AttrStyle::Outer,
path: ast::Path::from_ident(ast::Ident::new(Symbol::intern("prelude_import"), span)), path: ast::Path::from_ident(ast::Ident::new(sym::prelude_import, span)),
tokens: TokenStream::empty(), tokens: TokenStream::empty(),
id: attr::mk_attr_id(), id: attr::mk_attr_id(),
is_sugared_doc: false, is_sugared_doc: false,

View File

@ -283,12 +283,8 @@ fn generate_test_harness(sess: &ParseSess,
mark.set_expn_info(ExpnInfo { mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern("test_case")), format: MacroAttribute(sym::test_case),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::main, sym::test, sym::rustc_attrs].into()),
Symbol::intern("main"),
Symbol::intern("test"),
Symbol::intern("rustc_attrs"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition: sess.edition, edition: sess.edition,
@ -347,14 +343,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
let call_test_main = ecx.stmt_expr(call_test_main); let call_test_main = ecx.stmt_expr(call_test_main);
// #![main] // #![main]
let main_meta = ecx.meta_word(sp, Symbol::intern("main")); let main_meta = ecx.meta_word(sp, sym::main);
let main_attr = ecx.attribute(sp, main_meta); let main_attr = ecx.attribute(sp, main_meta);
// extern crate test as test_gensym // extern crate test as test_gensym
let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp, let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp,
test_id, test_id,
vec![], vec![],
ast::ItemKind::ExternCrate(Some(Symbol::intern("test"))) ast::ItemKind::ExternCrate(Some(sym::test))
)); ));
// pub fn main() { ... } // pub fn main() { ... }

View File

@ -11,7 +11,7 @@ use syntax::ext::base::{self, *};
use syntax::feature_gate; use syntax::feature_gate;
use syntax::parse::{self, token}; use syntax::parse::{self, token};
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::{Symbol, sym}; use syntax::symbol::{kw, sym, Symbol};
use syntax::ast::AsmDialect; use syntax::ast::AsmDialect;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
@ -93,7 +93,7 @@ fn parse_inline_asm<'a>(
}) })
.unwrap_or(tts.len()); .unwrap_or(tts.len());
let mut p = cx.new_parser_from_tts(&tts[first_colon..]); let mut p = cx.new_parser_from_tts(&tts[first_colon..]);
let mut asm = Symbol::intern(""); let mut asm = kw::Invalid;
let mut asm_str_style = None; let mut asm_str_style = None;
let mut outputs = Vec::new(); let mut outputs = Vec::new();
let mut inputs = Vec::new(); let mut inputs = Vec::new();

View File

@ -8,7 +8,7 @@ use syntax::parse::token::{self, Token};
use syntax::parse::parser::Parser; use syntax::parse::parser::Parser;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::{sym, Symbol};
use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::tokenstream::{TokenStream, TokenTree};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
@ -27,7 +27,7 @@ pub fn expand_assert<'cx>(
let sp = sp.apply_mark(cx.current_expansion.mark); let sp = sp.apply_mark(cx.current_expansion.mark);
let panic_call = Mac_ { let panic_call = Mac_ {
path: Path::from_ident(Ident::new(Symbol::intern("panic"), sp)), path: Path::from_ident(Ident::new(sym::panic, sp)),
tts: custom_message.unwrap_or_else(|| { tts: custom_message.unwrap_or_else(|| {
TokenStream::from(TokenTree::Token( TokenStream::from(TokenTree::Token(
DUMMY_SP, DUMMY_SP,

View File

@ -7,7 +7,7 @@ use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::{kw, sym};
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
@ -76,7 +76,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
_ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"), _ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"),
} }
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,

View File

@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem, GenericArg};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
@ -14,9 +14,9 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden")); let hidden = cx.meta_list_item_word(span, sym::hidden);
let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]); let doc = cx.meta_list(span, sym::doc, vec![hidden]);
let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)]; let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,

View File

@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
@ -14,7 +14,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,

View File

@ -6,7 +6,7 @@ use syntax::ast::{BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
@ -62,7 +62,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
macro_rules! md { macro_rules! md {
($name:expr, $f:ident) => { { ($name:expr, $f:ident) => { {
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
MethodDef { MethodDef {
name: $name, name: $name,

View File

@ -8,7 +8,7 @@ use syntax::ast::{self, BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
@ -18,7 +18,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
macro_rules! md { macro_rules! md {
($name:expr, $op:expr, $equal:expr) => { { ($name:expr, $op:expr, $equal:expr) => { {
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
MethodDef { MethodDef {
name: $name, name: $name,
@ -42,7 +42,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
vec![Box::new(ordering_ty)], vec![Box::new(ordering_ty)],
PathKind::Std)); PathKind::Std));
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let partial_cmp_def = MethodDef { let partial_cmp_def = MethodDef {

View File

@ -9,6 +9,7 @@ use syntax::ast::{Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>, pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>,
@ -82,7 +83,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
let expr = cx.expr_method_call(span, let expr = cx.expr_method_call(span,
builder_expr.clone(), builder_expr.clone(),
Ident::from_str("field"), Ident::with_empty_ctxt(sym::field),
vec![field]); vec![field]);
// Use `let _ = expr;` to avoid triggering the // Use `let _ = expr;` to avoid triggering the
@ -106,7 +107,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
let field = cx.expr_addr_of(field.span, field); let field = cx.expr_addr_of(field.span, field);
let expr = cx.expr_method_call(span, let expr = cx.expr_method_call(span,
builder_expr.clone(), builder_expr.clone(),
Ident::from_str("field"), Ident::with_empty_ctxt(sym::field),
vec![name, field]); vec![name, field]);
stmts.push(stmt_let_undescore(cx, span, expr)); stmts.push(stmt_let_undescore(cx, span, expr));
} }

View File

@ -6,7 +6,7 @@ use syntax::ast::{Expr, MetaItem};
use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt}; use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::sym;
use syntax::span_err; use syntax::span_err;
use syntax_pos::Span; use syntax_pos::Span;
@ -15,7 +15,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
let inline = cx.meta_word(span, Symbol::intern("inline")); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,

View File

@ -666,14 +666,13 @@ impl<'a> TraitDef<'a> {
let self_type = cx.ty_path(path); let self_type = cx.ty_path(path);
let attr = cx.attribute(self.span, let attr = cx.attribute(self.span,
cx.meta_word(self.span, cx.meta_word(self.span, sym::automatically_derived));
Symbol::intern("automatically_derived")));
// Just mark it now since we know that it'll end up used downstream // Just mark it now since we know that it'll end up used downstream
attr::mark_used(&attr); attr::mark_used(&attr);
let opt_trait_ref = Some(trait_ref); let opt_trait_ref = Some(trait_ref);
let unused_qual = { let unused_qual = {
let word = cx.meta_list_item_word(self.span, Symbol::intern("unused_qualifications")); let word = cx.meta_list_item_word(self.span, Symbol::intern("unused_qualifications"));
cx.attribute(self.span, cx.meta_list(self.span, Symbol::intern("allow"), vec![word])) cx.attribute(self.span, cx.meta_list(self.span, sym::allow, vec![word]))
}; };
let mut a = vec![attr, unused_qual]; let mut a = vec![attr, unused_qual];

View File

@ -145,7 +145,7 @@ fn call_intrinsic(cx: &ExtCtxt<'_>,
span = span.with_ctxt(cx.backtrace()); span = span.with_ctxt(cx.backtrace());
} else { // Avoid instability errors with user defined curstom derives, cc #36316 } else { // Avoid instability errors with user defined curstom derives, cc #36316
let mut info = cx.current_expansion.mark.expn_info().unwrap(); let mut info = cx.current_expansion.mark.expn_info().unwrap();
info.allow_internal_unstable = Some(vec![Symbol::intern("core_intrinsics")].into()); info.allow_internal_unstable = Some(vec![sym::core_intrinsics].into());
let mark = Mark::fresh(Mark::root()); let mark = Mark::fresh(Mark::root());
mark.set_expn_info(info); mark.set_expn_info(info);
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));

View File

@ -42,8 +42,8 @@ pub mod proc_macro_impl;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier}; use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier};
use syntax::symbol::Symbol;
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::symbol::{sym, Symbol};
pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
user_exts: Vec<NamedSyntaxExtension>, user_exts: Vec<NamedSyntaxExtension>,
@ -93,30 +93,26 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
assert: assert::expand_assert, assert: assert::expand_assert,
} }
register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand))); register(sym::test_case, MultiModifier(Box::new(test_case::expand)));
register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test))); register(sym::test, MultiModifier(Box::new(test::expand_test)));
register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench))); register(sym::bench, MultiModifier(Box::new(test::expand_bench)));
// format_args uses `unstable` things internally. // format_args uses `unstable` things internally.
register(Symbol::intern("format_args"), register(Symbol::intern("format_args"),
NormalTT { NormalTT {
expander: Box::new(format::expand_format_args), expander: Box::new(format::expand_format_args),
def_info: None, def_info: None,
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::fmt_internals].into()),
Symbol::intern("fmt_internals"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
unstable_feature: None, unstable_feature: None,
edition, edition,
}); });
register(Symbol::intern("format_args_nl"), register(sym::format_args_nl,
NormalTT { NormalTT {
expander: Box::new(format::expand_format_args_nl), expander: Box::new(format::expand_format_args_nl),
def_info: None, def_info: None,
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::fmt_internals].into()),
Symbol::intern("fmt_internals"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
unstable_feature: None, unstable_feature: None,

View File

@ -351,9 +351,9 @@ fn mk_decls(
mark.set_expn_info(ExpnInfo { mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern("proc_macro")), format: MacroAttribute(sym::proc_macro),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![
Symbol::intern("rustc_attrs"), sym::rustc_attrs,
Symbol::intern("proc_macro_internals"), Symbol::intern("proc_macro_internals"),
].into()), ].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
@ -420,7 +420,7 @@ fn mk_decls(
ast::Mutability::Immutable, ast::Mutability::Immutable,
cx.expr_vec_slice(span, decls), cx.expr_vec_slice(span, decls),
).map(|mut i| { ).map(|mut i| {
let attr = cx.meta_word(span, Symbol::intern("rustc_proc_macro_decls")); let attr = cx.meta_word(span, sym::rustc_proc_macro_decls);
i.attrs.push(cx.attribute(span, attr)); i.attrs.push(cx.attribute(span, attr));
i.vis = respan(span, ast::VisibilityKind::Public); i.vis = respan(span, ast::VisibilityKind::Public);
i i

View File

@ -14,7 +14,7 @@ use syntax::parse::lexer::comments;
use syntax::parse::{self, token, ParseSess}; use syntax::parse::{self, token, ParseSess};
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint}; use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
use syntax_pos::hygiene::{SyntaxContext, Transparency}; use syntax_pos::hygiene::{SyntaxContext, Transparency};
use syntax_pos::symbol::{kw, Symbol}; use syntax_pos::symbol::{kw, sym, Symbol};
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span}; use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
trait FromInternal<T> { trait FromInternal<T> {
@ -159,7 +159,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
escaped.extend(ch.escape_debug()); escaped.extend(ch.escape_debug());
} }
let stream = vec![ let stream = vec![
Ident(ast::Ident::new(Symbol::intern("doc"), span), false), Ident(ast::Ident::new(sym::doc, span), false),
Eq, Eq,
Token::lit(token::Str, Symbol::intern(&escaped), None), Token::lit(token::Str, Symbol::intern(&escaped), None),
] ]

View File

@ -65,11 +65,8 @@ pub fn expand_test_or_bench(
mark.set_expn_info(ExpnInfo { mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern("test")), format: MacroAttribute(sym::test),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::test].into()),
Symbol::intern("rustc_attrs"),
Symbol::intern("test"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition: cx.parse_sess.edition, edition: cx.parse_sess.edition,
@ -130,11 +127,11 @@ pub fn expand_test_or_bench(
let mut test_const = cx.item(sp, ast::Ident::new(item.ident.name, sp).gensym(), let mut test_const = cx.item(sp, ast::Ident::new(item.ident.name, sp).gensym(),
vec![ vec![
// #[cfg(test)] // #[cfg(test)]
cx.attribute(attr_sp, cx.meta_list(attr_sp, Symbol::intern("cfg"), vec![ cx.attribute(attr_sp, cx.meta_list(attr_sp, sym::cfg, vec![
cx.meta_list_item_word(attr_sp, Symbol::intern("test")) cx.meta_list_item_word(attr_sp, sym::test)
])), ])),
// #[rustc_test_marker] // #[rustc_test_marker]
cx.attribute(attr_sp, cx.meta_word(attr_sp, Symbol::intern("rustc_test_marker"))), cx.attribute(attr_sp, cx.meta_word(attr_sp, sym::rustc_test_marker)),
], ],
// const $ident: test::TestDescAndFn = // const $ident: test::TestDescAndFn =
ast::ItemKind::Const(cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), ast::ItemKind::Const(cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
@ -180,7 +177,7 @@ pub fn expand_test_or_bench(
let test_extern = cx.item(sp, let test_extern = cx.item(sp,
test_id, test_id,
vec![], vec![],
ast::ItemKind::ExternCrate(Some(Symbol::intern("test"))) ast::ItemKind::ExternCrate(Some(sym::test))
); );
log::debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const)); log::debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const));

View File

@ -14,7 +14,7 @@ use syntax::ext::build::AstBuilder;
use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::ast; use syntax::ast;
use syntax::source_map::respan; use syntax::source_map::respan;
use syntax::symbol::{Symbol, sym}; use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
use syntax::source_map::{ExpnInfo, MacroAttribute}; use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::feature_gate; use syntax::feature_gate;
@ -40,11 +40,8 @@ pub fn expand(
mark.set_expn_info(ExpnInfo { mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
def_site: None, def_site: None,
format: MacroAttribute(Symbol::intern("test_case")), format: MacroAttribute(sym::test_case),
allow_internal_unstable: Some(vec![ allow_internal_unstable: Some(vec![sym::test, sym::rustc_attrs].into()),
Symbol::intern("test"),
Symbol::intern("rustc_attrs"),
].into()),
allow_internal_unsafe: false, allow_internal_unsafe: false,
local_inner_macros: false, local_inner_macros: false,
edition: ecx.parse_sess.edition, edition: ecx.parse_sess.edition,
@ -59,7 +56,7 @@ pub fn expand(
item.ident = item.ident.gensym(); item.ident = item.ident.gensym();
item.attrs.push( item.attrs.push(
ecx.attribute(sp, ecx.attribute(sp,
ecx.meta_word(sp, Symbol::intern("rustc_test_marker"))) ecx.meta_word(sp, sym::rustc_test_marker))
); );
item item
}); });

View File

@ -145,6 +145,7 @@ symbols! {
automatically_derived, automatically_derived,
avx512_target_feature, avx512_target_feature,
await_macro, await_macro,
bench,
bin, bin,
bind_by_move_pattern_guards, bind_by_move_pattern_guards,
block, block,
@ -252,8 +253,10 @@ symbols! {
f64, f64,
feature, feature,
ffi_returns_twice, ffi_returns_twice,
field,
field_init_shorthand, field_init_shorthand,
file, file,
fmt_internals,
fn_must_use, fn_must_use,
forbid, forbid,
format_args_nl, format_args_nl,
@ -405,6 +408,7 @@ symbols! {
Output, Output,
overlapping_marker_traits, overlapping_marker_traits,
packed, packed,
panic,
panic_handler, panic_handler,
panic_impl, panic_impl,
panic_implementation, panic_implementation,
@ -430,6 +434,7 @@ symbols! {
proc_dash_macro: "proc-macro", proc_dash_macro: "proc-macro",
proc_macro, proc_macro,
proc_macro_attribute, proc_macro_attribute,
proc_macro_def_site,
proc_macro_derive, proc_macro_derive,
proc_macro_expr, proc_macro_expr,
proc_macro_gen, proc_macro_gen,
@ -568,6 +573,7 @@ symbols! {
test, test,
test_2018_feature, test_2018_feature,
test_accepted_feature, test_accepted_feature,
test_case,
test_removed_feature, test_removed_feature,
test_runner, test_runner,
thread_local, thread_local,