Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=petrochenkov
Avoid more symbol interning r? @petrochenkov
This commit is contained in:
commit
ab7cf71d4c
50 changed files with 299 additions and 228 deletions
|
@ -3009,6 +3009,7 @@ dependencies = [
|
||||||
"rustc_cratesio_shim 0.0.0",
|
"rustc_cratesio_shim 0.0.0",
|
||||||
"rustc_data_structures 0.0.0",
|
"rustc_data_structures 0.0.0",
|
||||||
"serialize 0.0.0",
|
"serialize 0.0.0",
|
||||||
|
"syntax_pos 0.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -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());
|
||||||
|
@ -2958,7 +2956,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
ident: match f.ident {
|
ident: match f.ident {
|
||||||
Some(ident) => ident,
|
Some(ident) => ident,
|
||||||
// FIXME(jseyfried): positional field hygiene
|
// FIXME(jseyfried): positional field hygiene
|
||||||
None => Ident::new(Symbol::intern(&index.to_string()), f.span),
|
None => Ident::new(sym::integer(index), f.span),
|
||||||
},
|
},
|
||||||
vis: self.lower_visibility(&f.vis, None),
|
vis: self.lower_visibility(&f.vis, None),
|
||||||
ty: self.lower_ty(&f.ty, ImplTraitContext::disallowed()),
|
ty: self.lower_ty(&f.ty, ImplTraitContext::disallowed()),
|
||||||
|
@ -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(
|
||||||
|
|
|
@ -5,8 +5,7 @@ use crate::session::CrateDisambiguator;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::Mark;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::symbol::kw;
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::symbol::Symbol;
|
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
|
@ -221,7 +220,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||||
_: &'a Generics, _: NodeId, _: Span) {
|
_: &'a Generics, _: NodeId, _: Span) {
|
||||||
for (index, field) in data.fields().iter().enumerate() {
|
for (index, field) in data.fields().iter().enumerate() {
|
||||||
let name = field.ident.map(|ident| ident.name)
|
let name = field.ident.map(|ident| ident.name)
|
||||||
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
|
.unwrap_or_else(|| sym::integer(index));
|
||||||
let def = self.create_def(field.id,
|
let def = self.create_def(field.id,
|
||||||
DefPathData::ValueNs(name.as_interned_str()),
|
DefPathData::ValueNs(name.as_interned_str()),
|
||||||
field.span);
|
field.span);
|
||||||
|
|
|
@ -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,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
||||||
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
||||||
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
|
let interior = InteriorField(FieldIndex(i, sym::integer(i)));
|
||||||
let subcmt = Rc::new(
|
let subcmt = Rc::new(
|
||||||
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||||
self.cat_pattern_(subcmt, &subpat, op)?;
|
self.cat_pattern_(subcmt, &subpat, op)?;
|
||||||
|
@ -1363,7 +1363,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
||||||
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
||||||
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
|
let interior = InteriorField(FieldIndex(i, sym::integer(i)));
|
||||||
let subcmt = Rc::new(
|
let subcmt = Rc::new(
|
||||||
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||||
self.cat_pattern_(subcmt, &subpat, op)?;
|
self.cat_pattern_(subcmt, &subpat, op)?;
|
||||||
|
|
|
@ -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: &[_]| {
|
||||||
|
|
|
@ -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()]) {
|
||||||
|
|
|
@ -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)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1439,8 +1439,8 @@ impl KeywordIdents {
|
||||||
{
|
{
|
||||||
let next_edition = match cx.sess.edition() {
|
let next_edition = match cx.sess.edition() {
|
||||||
Edition::Edition2015 => {
|
Edition::Edition2015 => {
|
||||||
match &ident.as_str()[..] {
|
match ident.name {
|
||||||
"async" | "await" | "try" => Edition::Edition2018,
|
kw::Async | kw::Await | kw::Try => Edition::Edition2018,
|
||||||
|
|
||||||
// rust-lang/rust#56327: Conservatively do not
|
// rust-lang/rust#56327: Conservatively do not
|
||||||
// attempt to report occurrences of `dyn` within
|
// attempt to report occurrences of `dyn` within
|
||||||
|
@ -1454,7 +1454,7 @@ impl KeywordIdents {
|
||||||
// its precise role in the parsed AST and thus are
|
// its precise role in the parsed AST and thus are
|
||||||
// assured this is truly an attempt to use it as
|
// assured this is truly an attempt to use it as
|
||||||
// an identifier.
|
// an identifier.
|
||||||
"dyn" if !under_macro => Edition::Edition2018,
|
kw::Dyn if !under_macro => Edition::Edition2018,
|
||||||
|
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
let mut keyword_stream = quote! {};
|
let mut keyword_stream = quote! {};
|
||||||
let mut symbols_stream = quote! {};
|
let mut symbols_stream = quote! {};
|
||||||
|
let mut digits_stream = quote! {};
|
||||||
let mut prefill_stream = quote! {};
|
let mut prefill_stream = quote! {};
|
||||||
let mut counter = 0u32;
|
let mut counter = 0u32;
|
||||||
let mut keys = HashSet::<String>::new();
|
let mut keys = HashSet::<String>::new();
|
||||||
|
@ -106,6 +107,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Generate the listed keywords.
|
||||||
for keyword in &input.keywords.0 {
|
for keyword in &input.keywords.0 {
|
||||||
let name = &keyword.name;
|
let name = &keyword.name;
|
||||||
let value = &keyword.value;
|
let value = &keyword.value;
|
||||||
|
@ -119,6 +121,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate the listed symbols.
|
||||||
for symbol in &input.symbols.0 {
|
for symbol in &input.symbols.0 {
|
||||||
let name = &symbol.name;
|
let name = &symbol.name;
|
||||||
let value = match &symbol.value {
|
let value = match &symbol.value {
|
||||||
|
@ -135,6 +138,19 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate symbols for the strings "0", "1", ..., "9".
|
||||||
|
for n in 0..10 {
|
||||||
|
let n = n.to_string();
|
||||||
|
check_dup(&n);
|
||||||
|
prefill_stream.extend(quote! {
|
||||||
|
#n,
|
||||||
|
});
|
||||||
|
digits_stream.extend(quote! {
|
||||||
|
Symbol::new(#counter),
|
||||||
|
});
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let tt = TokenStream::from(quote! {
|
let tt = TokenStream::from(quote! {
|
||||||
macro_rules! keywords {
|
macro_rules! keywords {
|
||||||
() => {
|
() => {
|
||||||
|
@ -145,6 +161,10 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
macro_rules! symbols {
|
macro_rules! symbols {
|
||||||
() => {
|
() => {
|
||||||
#symbols_stream
|
#symbols_stream
|
||||||
|
|
||||||
|
pub const digits_array: &[Symbol; 10] = &[
|
||||||
|
#digits_stream
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::fmt::Write;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
use syntax_pos::symbol::Symbol;
|
use syntax_pos::symbol::{sym, Symbol};
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use rustc::ty::layout::{self, Size, Align, TyLayout, LayoutOf, VariantIdx};
|
use rustc::ty::layout::{self, Size, Align, TyLayout, LayoutOf, VariantIdx};
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
|
@ -188,7 +188,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
|
||||||
|
|
||||||
PathElem::ClosureVar(name.unwrap_or_else(|| {
|
PathElem::ClosureVar(name.unwrap_or_else(|| {
|
||||||
// Fall back to showing the field index.
|
// Fall back to showing the field index.
|
||||||
Symbol::intern(&field.to_string())
|
sym::integer(field)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,4 @@ log = "0.4"
|
||||||
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
|
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
|
||||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||||
serialize = { path = "../libserialize" }
|
serialize = { path = "../libserialize" }
|
||||||
|
syntax_pos = { path = "../libsyntax_pos" }
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::fmt;
|
||||||
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
|
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
|
||||||
|
|
||||||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||||
|
use syntax_pos::symbol::{sym, Symbol};
|
||||||
|
|
||||||
pub mod call;
|
pub mod call;
|
||||||
|
|
||||||
|
@ -552,6 +553,13 @@ impl FloatTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_symbol(self) -> Symbol {
|
||||||
|
match self {
|
||||||
|
FloatTy::F32 => sym::f32,
|
||||||
|
FloatTy::F64 => sym::f64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn bit_width(self) -> usize {
|
pub fn bit_width(self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
FloatTy::F32 => 32,
|
FloatTy::F32 => 32,
|
||||||
|
|
|
@ -2697,16 +2697,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, ast::Ident) {
|
fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, ast::Ident) {
|
||||||
let (tr, name) = match (op, is_mut) {
|
let (tr, name) = match (op, is_mut) {
|
||||||
(PlaceOp::Deref, false) =>
|
(PlaceOp::Deref, false) => (self.tcx.lang_items().deref_trait(), sym::deref),
|
||||||
(self.tcx.lang_items().deref_trait(), "deref"),
|
(PlaceOp::Deref, true) => (self.tcx.lang_items().deref_mut_trait(), sym::deref_mut),
|
||||||
(PlaceOp::Deref, true) =>
|
(PlaceOp::Index, false) => (self.tcx.lang_items().index_trait(), sym::index),
|
||||||
(self.tcx.lang_items().deref_mut_trait(), "deref_mut"),
|
(PlaceOp::Index, true) => (self.tcx.lang_items().index_mut_trait(), sym::index_mut),
|
||||||
(PlaceOp::Index, false) =>
|
|
||||||
(self.tcx.lang_items().index_trait(), "index"),
|
|
||||||
(PlaceOp::Index, true) =>
|
|
||||||
(self.tcx.lang_items().index_mut_trait(), "index_mut"),
|
|
||||||
};
|
};
|
||||||
(tr, ast::Ident::from_str(name))
|
(tr, ast::Ident::with_empty_ctxt(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_overloaded_place_op(&self,
|
fn try_overloaded_place_op(&self,
|
||||||
|
@ -4948,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 {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::parse::token;
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
use crate::symbol::{kw, Symbol};
|
use crate::symbol::{kw, sym, Symbol};
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
|
@ -1531,6 +1531,17 @@ impl IntTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_symbol(&self) -> Symbol {
|
||||||
|
match *self {
|
||||||
|
IntTy::Isize => sym::isize,
|
||||||
|
IntTy::I8 => sym::i8,
|
||||||
|
IntTy::I16 => sym::i16,
|
||||||
|
IntTy::I32 => sym::i32,
|
||||||
|
IntTy::I64 => sym::i64,
|
||||||
|
IntTy::I128 => sym::i128,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn val_to_string(&self, val: i128) -> String {
|
pub fn val_to_string(&self, val: i128) -> String {
|
||||||
// Cast to a `u128` so we can correctly print `INT128_MIN`. All integral types
|
// Cast to a `u128` so we can correctly print `INT128_MIN`. All integral types
|
||||||
// are parsed as `u128`, so we wouldn't want to print an extra negative
|
// are parsed as `u128`, so we wouldn't want to print an extra negative
|
||||||
|
@ -1572,6 +1583,17 @@ impl UintTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_symbol(&self) -> Symbol {
|
||||||
|
match *self {
|
||||||
|
UintTy::Usize => sym::usize,
|
||||||
|
UintTy::U8 => sym::u8,
|
||||||
|
UintTy::U16 => sym::u16,
|
||||||
|
UintTy::U32 => sym::u32,
|
||||||
|
UintTy::U64 => sym::u64,
|
||||||
|
UintTy::U128 => sym::u128,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn val_to_string(&self, val: u128) -> String {
|
pub fn val_to_string(&self, val: u128) -> String {
|
||||||
format!("{}{}", val, self.ty_to_string())
|
format!("{}{}", val, self.ty_to_string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> {
|
||||||
pub fn ident_of(&self, st: &str) -> ast::Ident {
|
pub fn ident_of(&self, st: &str) -> ast::Ident {
|
||||||
ast::Ident::from_str(st)
|
ast::Ident::from_str(st)
|
||||||
}
|
}
|
||||||
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
|
pub fn std_path(&self, components: &[Symbol]) -> Vec<ast::Ident> {
|
||||||
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
|
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
|
||||||
iter::once(Ident::new(kw::DollarCrate, def_site))
|
iter::once(Ident::new(kw::DollarCrate, def_site))
|
||||||
.chain(components.iter().map(|s| self.ident_of(s)))
|
.chain(components.iter().map(|&s| Ident::with_empty_ctxt(s)))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
pub fn name_of(&self, st: &str) -> ast::Name {
|
pub fn name_of(&self, st: &str) -> ast::Name {
|
||||||
|
|
|
@ -3,11 +3,11 @@ use crate::attr;
|
||||||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
use crate::ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::{Symbol, kw};
|
use crate::symbol::{kw, sym, Symbol};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use syntax_pos::{Pos, Span, DUMMY_SP};
|
use syntax_pos::{Pos, Span};
|
||||||
|
|
||||||
pub trait AstBuilder {
|
pub trait AstBuilder {
|
||||||
// paths
|
// paths
|
||||||
|
@ -49,7 +49,6 @@ pub trait AstBuilder {
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
mutbl: ast::Mutability) -> P<ast::Ty>;
|
mutbl: ast::Mutability) -> P<ast::Ty>;
|
||||||
|
|
||||||
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
|
|
||||||
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
||||||
|
|
||||||
fn typaram(&self,
|
fn typaram(&self,
|
||||||
|
@ -425,15 +424,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
|
ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
|
|
||||||
self.ty_path(
|
|
||||||
self.path_all(DUMMY_SP,
|
|
||||||
true,
|
|
||||||
self.std_path(&["option", "Option"]),
|
|
||||||
vec![ast::GenericArg::Type(ty)],
|
|
||||||
Vec::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ty_infer(&self, span: Span) -> P<ast::Ty> {
|
fn ty_infer(&self, span: Span) -> P<ast::Ty> {
|
||||||
self.ty(span, ast::TyKind::Infer)
|
self.ty(span, ast::TyKind::Infer)
|
||||||
}
|
}
|
||||||
|
@ -735,7 +725,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.expr(sp, ast::ExprKind::Array(exprs))
|
self.expr(sp, ast::ExprKind::Array(exprs))
|
||||||
}
|
}
|
||||||
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
|
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
|
||||||
self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
|
self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]),
|
||||||
Vec::new())
|
Vec::new())
|
||||||
}
|
}
|
||||||
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
|
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
|
||||||
|
@ -751,12 +741,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
|
|
||||||
|
|
||||||
fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
||||||
let some = self.std_path(&["option", "Option", "Some"]);
|
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
|
||||||
self.expr_call_global(sp, some, vec![expr])
|
self.expr_call_global(sp, some, vec![expr])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_none(&self, sp: Span) -> P<ast::Expr> {
|
fn expr_none(&self, sp: Span) -> P<ast::Expr> {
|
||||||
let none = self.std_path(&["option", "Option", "None"]);
|
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
|
||||||
let none = self.path_global(sp, none);
|
let none = self.path_global(sp, none);
|
||||||
self.expr_path(none)
|
self.expr_path(none)
|
||||||
}
|
}
|
||||||
|
@ -780,7 +770,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
|
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
|
||||||
self.expr_call_global(
|
self.expr_call_global(
|
||||||
span,
|
span,
|
||||||
self.std_path(&["rt", "begin_panic"]),
|
self.std_path(&[sym::rt, sym::begin_panic]),
|
||||||
vec![
|
vec![
|
||||||
self.expr_str(span, msg),
|
self.expr_str(span, msg),
|
||||||
expr_loc_ptr])
|
expr_loc_ptr])
|
||||||
|
@ -791,19 +781,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
||||||
let ok = self.std_path(&["result", "Result", "Ok"]);
|
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
|
||||||
self.expr_call_global(sp, ok, vec![expr])
|
self.expr_call_global(sp, ok, vec![expr])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
|
||||||
let err = self.std_path(&["result", "Result", "Err"]);
|
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
|
||||||
self.expr_call_global(sp, err, vec![expr])
|
self.expr_call_global(sp, err, vec![expr])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
|
fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
|
||||||
let ok = self.std_path(&["result", "Result", "Ok"]);
|
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
|
||||||
let ok_path = self.path_global(sp, ok);
|
let ok_path = self.path_global(sp, ok);
|
||||||
let err = self.std_path(&["result", "Result", "Err"]);
|
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
|
||||||
let err_path = self.path_global(sp, err);
|
let err_path = self.path_global(sp, err);
|
||||||
|
|
||||||
let binding_variable = self.ident_of("__try_var");
|
let binding_variable = self.ident_of("__try_var");
|
||||||
|
@ -867,25 +857,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
||||||
let some = self.std_path(&["option", "Option", "Some"]);
|
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
|
||||||
let path = self.path_global(span, some);
|
let path = self.path_global(span, some);
|
||||||
self.pat_tuple_struct(span, path, vec![pat])
|
self.pat_tuple_struct(span, path, vec![pat])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_none(&self, span: Span) -> P<ast::Pat> {
|
fn pat_none(&self, span: Span) -> P<ast::Pat> {
|
||||||
let some = self.std_path(&["option", "Option", "None"]);
|
let some = self.std_path(&[sym::option, sym::Option, sym::None]);
|
||||||
let path = self.path_global(span, some);
|
let path = self.path_global(span, some);
|
||||||
self.pat_path(span, path)
|
self.pat_path(span, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
||||||
let some = self.std_path(&["result", "Result", "Ok"]);
|
let some = self.std_path(&[sym::result, sym::Result, sym::Ok]);
|
||||||
let path = self.path_global(span, some);
|
let path = self.path_global(span, some);
|
||||||
self.pat_tuple_struct(span, path, vec![pat])
|
self.pat_tuple_struct(span, path, vec![pat])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
||||||
let some = self.std_path(&["result", "Result", "Err"]);
|
let some = self.std_path(&[sym::result, sym::Result, sym::Err]);
|
||||||
let path = self.path_global(span, some);
|
let path = self.path_global(span, some);
|
||||||
self.pat_tuple_struct(span, path, vec![pat])
|
self.pat_tuple_struct(span, path, vec![pat])
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -80,7 +80,7 @@ use crate::parse::{Directory, ParseSess};
|
||||||
use crate::parse::parser::{Parser, PathStyle};
|
use crate::parse::parser::{Parser, PathStyle};
|
||||||
use crate::parse::token::{self, DocComment, Nonterminal, Token};
|
use crate::parse::token::{self, DocComment, Nonterminal, Token};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::symbol::kw;
|
use crate::symbol::{kw, sym, Symbol};
|
||||||
use crate::tokenstream::{DelimSpan, TokenStream};
|
use crate::tokenstream::{DelimSpan, TokenStream};
|
||||||
|
|
||||||
use errors::FatalError;
|
use errors::FatalError;
|
||||||
|
@ -598,7 +598,7 @@ fn inner_parse_loop<'root, 'tt>(
|
||||||
TokenTree::MetaVarDecl(_, _, id) => {
|
TokenTree::MetaVarDecl(_, _, id) => {
|
||||||
// Built-in nonterminals never start with these tokens,
|
// Built-in nonterminals never start with these tokens,
|
||||||
// so we can eliminate them from consideration.
|
// so we can eliminate them from consideration.
|
||||||
if may_begin_with(&*id.as_str(), token) {
|
if may_begin_with(id.name, token) {
|
||||||
bb_items.push(item);
|
bb_items.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -791,7 +791,7 @@ pub fn parse(
|
||||||
let match_cur = item.match_cur;
|
let match_cur = item.match_cur;
|
||||||
item.push_match(
|
item.push_match(
|
||||||
match_cur,
|
match_cur,
|
||||||
MatchedNonterminal(Lrc::new(parse_nt(&mut parser, span, &ident.as_str()))),
|
MatchedNonterminal(Lrc::new(parse_nt(&mut parser, span, ident.name))),
|
||||||
);
|
);
|
||||||
item.idx += 1;
|
item.idx += 1;
|
||||||
item.match_cur += 1;
|
item.match_cur += 1;
|
||||||
|
@ -819,7 +819,7 @@ fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> {
|
||||||
///
|
///
|
||||||
/// Returning `false` is a *stability guarantee* that such a matcher will *never* begin with that
|
/// Returning `false` is a *stability guarantee* that such a matcher will *never* begin with that
|
||||||
/// token. Be conservative (return true) if not sure.
|
/// token. Be conservative (return true) if not sure.
|
||||||
fn may_begin_with(name: &str, token: &Token) -> bool {
|
fn may_begin_with(name: Symbol, token: &Token) -> bool {
|
||||||
/// Checks whether the non-terminal may contain a single (non-keyword) identifier.
|
/// Checks whether the non-terminal may contain a single (non-keyword) identifier.
|
||||||
fn may_be_ident(nt: &token::Nonterminal) -> bool {
|
fn may_be_ident(nt: &token::Nonterminal) -> bool {
|
||||||
match *nt {
|
match *nt {
|
||||||
|
@ -829,16 +829,16 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
match name {
|
match name {
|
||||||
"expr" => token.can_begin_expr(),
|
sym::expr => token.can_begin_expr(),
|
||||||
"ty" => token.can_begin_type(),
|
sym::ty => token.can_begin_type(),
|
||||||
"ident" => get_macro_ident(token).is_some(),
|
sym::ident => get_macro_ident(token).is_some(),
|
||||||
"literal" => token.can_begin_literal_or_bool(),
|
sym::literal => token.can_begin_literal_or_bool(),
|
||||||
"vis" => match *token {
|
sym::vis => match *token {
|
||||||
// The follow-set of :vis + "priv" keyword + interpolated
|
// The follow-set of :vis + "priv" keyword + interpolated
|
||||||
Token::Comma | Token::Ident(..) | Token::Interpolated(_) => true,
|
Token::Comma | Token::Ident(..) | Token::Interpolated(_) => true,
|
||||||
_ => token.can_begin_type(),
|
_ => token.can_begin_type(),
|
||||||
},
|
},
|
||||||
"block" => match *token {
|
sym::block => match *token {
|
||||||
Token::OpenDelim(token::Brace) => true,
|
Token::OpenDelim(token::Brace) => true,
|
||||||
Token::Interpolated(ref nt) => match **nt {
|
Token::Interpolated(ref nt) => match **nt {
|
||||||
token::NtItem(_)
|
token::NtItem(_)
|
||||||
|
@ -852,7 +852,7 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
"path" | "meta" => match *token {
|
sym::path | sym::meta => match *token {
|
||||||
Token::ModSep | Token::Ident(..) => true,
|
Token::ModSep | Token::Ident(..) => true,
|
||||||
Token::Interpolated(ref nt) => match **nt {
|
Token::Interpolated(ref nt) => match **nt {
|
||||||
token::NtPath(_) | token::NtMeta(_) => true,
|
token::NtPath(_) | token::NtMeta(_) => true,
|
||||||
|
@ -860,7 +860,7 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
"pat" => match *token {
|
sym::pat => match *token {
|
||||||
Token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
Token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
||||||
Token::OpenDelim(token::Paren) | // tuple pattern
|
Token::OpenDelim(token::Paren) | // tuple pattern
|
||||||
Token::OpenDelim(token::Bracket) | // slice pattern
|
Token::OpenDelim(token::Bracket) | // slice pattern
|
||||||
|
@ -876,7 +876,7 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
|
||||||
Token::Interpolated(ref nt) => may_be_ident(nt),
|
Token::Interpolated(ref nt) => may_be_ident(nt),
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
"lifetime" => match *token {
|
sym::lifetime => match *token {
|
||||||
Token::Lifetime(_) => true,
|
Token::Lifetime(_) => true,
|
||||||
Token::Interpolated(ref nt) => match **nt {
|
Token::Interpolated(ref nt) => match **nt {
|
||||||
token::NtLifetime(_) | token::NtTT(_) => true,
|
token::NtLifetime(_) | token::NtTT(_) => true,
|
||||||
|
@ -903,34 +903,34 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// The parsed non-terminal.
|
/// The parsed non-terminal.
|
||||||
fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> Nonterminal {
|
||||||
if name == "tt" {
|
if name == sym::tt {
|
||||||
return token::NtTT(p.parse_token_tree());
|
return token::NtTT(p.parse_token_tree());
|
||||||
}
|
}
|
||||||
// check at the beginning and the parser checks after each bump
|
// check at the beginning and the parser checks after each bump
|
||||||
p.process_potential_macro_variable();
|
p.process_potential_macro_variable();
|
||||||
match name {
|
match name {
|
||||||
"item" => match panictry!(p.parse_item()) {
|
sym::item => match panictry!(p.parse_item()) {
|
||||||
Some(i) => token::NtItem(i),
|
Some(i) => token::NtItem(i),
|
||||||
None => {
|
None => {
|
||||||
p.fatal("expected an item keyword").emit();
|
p.fatal("expected an item keyword").emit();
|
||||||
FatalError.raise();
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"block" => token::NtBlock(panictry!(p.parse_block())),
|
sym::block => token::NtBlock(panictry!(p.parse_block())),
|
||||||
"stmt" => match panictry!(p.parse_stmt()) {
|
sym::stmt => match panictry!(p.parse_stmt()) {
|
||||||
Some(s) => token::NtStmt(s),
|
Some(s) => token::NtStmt(s),
|
||||||
None => {
|
None => {
|
||||||
p.fatal("expected a statement").emit();
|
p.fatal("expected a statement").emit();
|
||||||
FatalError.raise();
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pat" => token::NtPat(panictry!(p.parse_pat(None))),
|
sym::pat => token::NtPat(panictry!(p.parse_pat(None))),
|
||||||
"expr" => token::NtExpr(panictry!(p.parse_expr())),
|
sym::expr => token::NtExpr(panictry!(p.parse_expr())),
|
||||||
"literal" => token::NtLiteral(panictry!(p.parse_literal_maybe_minus())),
|
sym::literal => token::NtLiteral(panictry!(p.parse_literal_maybe_minus())),
|
||||||
"ty" => token::NtTy(panictry!(p.parse_ty())),
|
sym::ty => token::NtTy(panictry!(p.parse_ty())),
|
||||||
// this could be handled like a token, since it is one
|
// this could be handled like a token, since it is one
|
||||||
"ident" => if let Some((ident, is_raw)) = get_macro_ident(&p.token) {
|
sym::ident => if let Some((ident, is_raw)) = get_macro_ident(&p.token) {
|
||||||
let span = p.span;
|
let span = p.span;
|
||||||
p.bump();
|
p.bump();
|
||||||
token::NtIdent(Ident::new(ident.name, span), is_raw)
|
token::NtIdent(Ident::new(ident.name, span), is_raw)
|
||||||
|
@ -939,10 +939,10 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
||||||
p.fatal(&format!("expected ident, found {}", &token_str)).emit();
|
p.fatal(&format!("expected ident, found {}", &token_str)).emit();
|
||||||
FatalError.raise()
|
FatalError.raise()
|
||||||
}
|
}
|
||||||
"path" => token::NtPath(panictry!(p.parse_path(PathStyle::Type))),
|
sym::path => token::NtPath(panictry!(p.parse_path(PathStyle::Type))),
|
||||||
"meta" => token::NtMeta(panictry!(p.parse_meta_item())),
|
sym::meta => token::NtMeta(panictry!(p.parse_meta_item())),
|
||||||
"vis" => token::NtVis(panictry!(p.parse_visibility(true))),
|
sym::vis => token::NtVis(panictry!(p.parse_visibility(true))),
|
||||||
"lifetime" => if p.check_lifetime() {
|
sym::lifetime => if p.check_lifetime() {
|
||||||
token::NtLifetime(p.expect_lifetime().ident)
|
token::NtLifetime(p.expect_lifetime().ident)
|
||||||
} else {
|
} else {
|
||||||
let token_str = pprust::token_to_string(&p.token);
|
let token_str = pprust::token_to_string(&p.token);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, Token
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::source_map::Spanned;
|
use crate::source_map::Spanned;
|
||||||
use crate::symbol::kw;
|
use crate::symbol::{kw, sym};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
use crate::util::parser::AssocOp;
|
use crate::util::parser::AssocOp;
|
||||||
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
||||||
|
@ -263,7 +263,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
self.last_unexpected_token_span = Some(self.span);
|
self.last_unexpected_token_span = Some(self.span);
|
||||||
let mut err = self.fatal(&msg_exp);
|
let mut err = self.fatal(&msg_exp);
|
||||||
if self.token.is_ident_named("and") {
|
if self.token.is_ident_named(sym::and) {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `&&` instead of `and` for the boolean operator",
|
"use `&&` instead of `and` for the boolean operator",
|
||||||
|
@ -271,7 +271,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.token.is_ident_named("or") {
|
if self.token.is_ident_named(sym::or) {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `||` instead of `or` for the boolean operator",
|
"use `||` instead of `or` for the boolean operator",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::ast::{self, Ident};
|
use crate::ast::{self, Ident};
|
||||||
use crate::parse::ParseSess;
|
use crate::parse::ParseSess;
|
||||||
use crate::parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use crate::symbol::Symbol;
|
use crate::symbol::{sym, Symbol};
|
||||||
use crate::parse::unescape;
|
use crate::parse::unescape;
|
||||||
use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char};
|
use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char};
|
||||||
|
|
||||||
|
@ -754,7 +754,7 @@ impl<'a> StringReader<'a> {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// just a 0
|
// just a 0
|
||||||
return (token::Integer, self.name_from(start_bpos));
|
return (token::Integer, sym::integer(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if c.is_digit(10) {
|
} else if c.is_digit(10) {
|
||||||
|
|
|
@ -171,12 +171,15 @@ impl LitKind {
|
||||||
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
|
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
|
||||||
pub fn to_lit_token(&self) -> token::Lit {
|
pub fn to_lit_token(&self) -> token::Lit {
|
||||||
let (kind, symbol, suffix) = match *self {
|
let (kind, symbol, suffix) = match *self {
|
||||||
LitKind::Str(string, ast::StrStyle::Cooked) => {
|
LitKind::Str(symbol, ast::StrStyle::Cooked) => {
|
||||||
let escaped = string.as_str().escape_default().to_string();
|
// Don't re-intern unless the escaped string is different.
|
||||||
(token::Str, Symbol::intern(&escaped), None)
|
let s = &symbol.as_str();
|
||||||
|
let escaped = s.escape_default().to_string();
|
||||||
|
let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) };
|
||||||
|
(token::Str, symbol, None)
|
||||||
}
|
}
|
||||||
LitKind::Str(string, ast::StrStyle::Raw(n)) => {
|
LitKind::Str(symbol, ast::StrStyle::Raw(n)) => {
|
||||||
(token::StrRaw(n), string, None)
|
(token::StrRaw(n), symbol, None)
|
||||||
}
|
}
|
||||||
LitKind::ByteStr(ref bytes) => {
|
LitKind::ByteStr(ref bytes) => {
|
||||||
let string = bytes.iter().cloned().flat_map(ascii::escape_default)
|
let string = bytes.iter().cloned().flat_map(ascii::escape_default)
|
||||||
|
@ -193,14 +196,14 @@ impl LitKind {
|
||||||
}
|
}
|
||||||
LitKind::Int(n, ty) => {
|
LitKind::Int(n, ty) => {
|
||||||
let suffix = match ty {
|
let suffix = match ty {
|
||||||
ast::LitIntType::Unsigned(ty) => Some(Symbol::intern(ty.ty_to_string())),
|
ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()),
|
||||||
ast::LitIntType::Signed(ty) => Some(Symbol::intern(ty.ty_to_string())),
|
ast::LitIntType::Signed(ty) => Some(ty.to_symbol()),
|
||||||
ast::LitIntType::Unsuffixed => None,
|
ast::LitIntType::Unsuffixed => None,
|
||||||
};
|
};
|
||||||
(token::Integer, Symbol::intern(&n.to_string()), suffix)
|
(token::Integer, sym::integer(n), suffix)
|
||||||
}
|
}
|
||||||
LitKind::Float(symbol, ty) => {
|
LitKind::Float(symbol, ty) => {
|
||||||
(token::Float, symbol, Some(Symbol::intern(ty.ty_to_string())))
|
(token::Float, symbol, Some(ty.to_symbol()))
|
||||||
}
|
}
|
||||||
LitKind::FloatUnsuffixed(symbol) => {
|
LitKind::FloatUnsuffixed(symbol) => {
|
||||||
(token::Float, symbol, None)
|
(token::Float, symbol, None)
|
||||||
|
|
|
@ -2759,7 +2759,7 @@ impl<'a> Parser<'a> {
|
||||||
let (span, e) = self.interpolated_or_expr_span(e)?;
|
let (span, e) = self.interpolated_or_expr_span(e)?;
|
||||||
(lo.to(span), ExprKind::Box(e))
|
(lo.to(span), ExprKind::Box(e))
|
||||||
}
|
}
|
||||||
token::Ident(..) if self.token.is_ident_named("not") => {
|
token::Ident(..) if self.token.is_ident_named(sym::not) => {
|
||||||
// `not` is just an ordinary identifier in Rust-the-language,
|
// `not` is just an ordinary identifier in Rust-the-language,
|
||||||
// but as `rustc`-the-compiler, we can issue clever diagnostics
|
// but as `rustc`-the-compiler, we can issue clever diagnostics
|
||||||
// for confused users who really want to say `!`
|
// for confused users who really want to say `!`
|
||||||
|
@ -4592,7 +4592,7 @@ impl<'a> Parser<'a> {
|
||||||
let do_not_suggest_help =
|
let do_not_suggest_help =
|
||||||
self.token.is_keyword(kw::In) || self.token == token::Colon;
|
self.token.is_keyword(kw::In) || self.token == token::Colon;
|
||||||
|
|
||||||
if self.token.is_ident_named("and") {
|
if self.token.is_ident_named(sym::and) {
|
||||||
e.span_suggestion_short(
|
e.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `&&` instead of `and` for the boolean operator",
|
"use `&&` instead of `and` for the boolean operator",
|
||||||
|
@ -4600,7 +4600,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.token.is_ident_named("or") {
|
if self.token.is_ident_named(sym::or) {
|
||||||
e.span_suggestion_short(
|
e.span_suggestion_short(
|
||||||
self.span,
|
self.span,
|
||||||
"use `||` instead of `or` for the boolean operator",
|
"use `||` instead of `or` for the boolean operator",
|
||||||
|
@ -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 {
|
||||||
|
|
|
@ -391,9 +391,9 @@ impl Token {
|
||||||
|
|
||||||
/// Returns `true` if the token is a identifier whose name is the given
|
/// Returns `true` if the token is a identifier whose name is the given
|
||||||
/// string slice.
|
/// string slice.
|
||||||
crate fn is_ident_named(&self, name: &str) -> bool {
|
crate fn is_ident_named(&self, name: Symbol) -> bool {
|
||||||
match self.ident() {
|
match self.ident() {
|
||||||
Some((ident, _)) => ident.as_str() == name,
|
Some((ident, _)) => ident.name == name,
|
||||||
None => false
|
None => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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() { ... }
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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, Symbol};
|
||||||
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,
|
||||||
|
@ -115,7 +115,7 @@ fn cs_clone_shallow(name: &str,
|
||||||
// set the expn ID so we can use the unstable struct.
|
// set the expn ID so we can use the unstable struct.
|
||||||
let span = span.with_ctxt(cx.backtrace());
|
let span = span.with_ctxt(cx.backtrace());
|
||||||
let assert_path = cx.path_all(span, true,
|
let assert_path = cx.path_all(span, true,
|
||||||
cx.std_path(&["clone", helper_name]),
|
cx.std_path(&[sym::clone, Symbol::intern(helper_name)]),
|
||||||
vec![GenericArg::Type(ty)], vec![]);
|
vec![GenericArg::Type(ty)], vec![]);
|
||||||
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
|
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ fn cs_clone(name: &str,
|
||||||
-> P<Expr> {
|
-> P<Expr> {
|
||||||
let ctor_path;
|
let ctor_path;
|
||||||
let all_fields;
|
let all_fields;
|
||||||
let fn_path = cx.std_path(&["clone", "Clone", "clone"]);
|
let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]);
|
||||||
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
|
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
|
||||||
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
|
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
|
||||||
cx.expr_call_global(field.span, fn_path.clone(), args)
|
cx.expr_call_global(field.span, fn_path.clone(), args)
|
||||||
|
|
|
@ -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, Symbol};
|
||||||
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,
|
||||||
|
@ -54,7 +54,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>,
|
||||||
// set the expn ID so we can use the unstable struct.
|
// set the expn ID so we can use the unstable struct.
|
||||||
let span = span.with_ctxt(cx.backtrace());
|
let span = span.with_ctxt(cx.backtrace());
|
||||||
let assert_path = cx.path_all(span, true,
|
let assert_path = cx.path_all(span, true,
|
||||||
cx.std_path(&["cmp", helper_name]),
|
cx.std_path(&[sym::cmp, Symbol::intern(helper_name)]),
|
||||||
vec![GenericArg::Type(ty)], vec![]);
|
vec![GenericArg::Type(ty)], vec![]);
|
||||||
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
|
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -55,9 +55,9 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>,
|
||||||
|
|
||||||
pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
||||||
let test_id = cx.ident_of("cmp").gensym();
|
let test_id = cx.ident_of("cmp").gensym();
|
||||||
let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
|
let equals_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
|
||||||
|
|
||||||
let cmp_path = cx.std_path(&["cmp", "Ord", "cmp"]);
|
let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);
|
||||||
|
|
||||||
// Builds:
|
// Builds:
|
||||||
//
|
//
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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, Symbol};
|
||||||
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 {
|
||||||
|
@ -114,11 +114,11 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
|
||||||
|
|
||||||
pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
||||||
let test_id = cx.ident_of("cmp").gensym();
|
let test_id = cx.ident_of("cmp").gensym();
|
||||||
let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
|
let ordering = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
|
||||||
let ordering_expr = cx.expr_path(ordering.clone());
|
let ordering_expr = cx.expr_path(ordering.clone());
|
||||||
let equals_expr = cx.expr_some(span, ordering_expr);
|
let equals_expr = cx.expr_some(span, ordering_expr);
|
||||||
|
|
||||||
let partial_cmp_path = cx.std_path(&["cmp", "PartialOrd", "partial_cmp"]);
|
let partial_cmp_path = cx.std_path(&[sym::cmp, sym::PartialOrd, sym::partial_cmp]);
|
||||||
|
|
||||||
// Builds:
|
// Builds:
|
||||||
//
|
//
|
||||||
|
@ -188,7 +188,8 @@ fn cs_op(less: bool,
|
||||||
span: Span,
|
span: Span,
|
||||||
substr: &Substructure<'_>) -> P<Expr> {
|
substr: &Substructure<'_>) -> P<Expr> {
|
||||||
let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| {
|
let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| {
|
||||||
cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name])))
|
cx.expr_path(cx.path_global(
|
||||||
|
span, cx.std_path(&[sym::cmp, sym::Ordering, Symbol::intern(name)])))
|
||||||
};
|
};
|
||||||
|
|
||||||
let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
|
let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
|
||||||
|
@ -198,9 +199,9 @@ fn cs_op(less: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
// `PartialOrd::partial_cmp(self.fi, other.fi)`
|
// `PartialOrd::partial_cmp(self.fi, other.fi)`
|
||||||
let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&["cmp",
|
let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::cmp,
|
||||||
"PartialOrd",
|
sym::PartialOrd,
|
||||||
"partial_cmp"])));
|
sym::partial_cmp])));
|
||||||
let cmp = cx.expr_call(span,
|
let cmp = cx.expr_call(span,
|
||||||
cmp_path,
|
cmp_path,
|
||||||
vec![cx.expr_addr_of(span, self_f),
|
vec![cx.expr_addr_of(span, self_f),
|
||||||
|
@ -208,9 +209,9 @@ fn cs_op(less: bool,
|
||||||
|
|
||||||
let default = ordering_path(cx, default);
|
let default = ordering_path(cx, default);
|
||||||
// `Option::unwrap_or(_, Ordering::Equal)`
|
// `Option::unwrap_or(_, Ordering::Equal)`
|
||||||
let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&["option",
|
let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::option,
|
||||||
"Option",
|
sym::Option,
|
||||||
"unwrap_or"])));
|
sym::unwrap_or])));
|
||||||
cx.expr_call(span, unwrap_path, vec![cmp, default])
|
cx.expr_call(span, unwrap_path, vec![cmp, default])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -256,9 +257,9 @@ fn cs_op(less: bool,
|
||||||
|
|
||||||
// `Ordering::then_with(Option::unwrap_or(..), ..)`
|
// `Ordering::then_with(Option::unwrap_or(..), ..)`
|
||||||
let then_with_path = cx.expr_path(cx.path_global(span,
|
let then_with_path = cx.expr_path(cx.path_global(span,
|
||||||
cx.std_path(&["cmp",
|
cx.std_path(&[sym::cmp,
|
||||||
"Ordering",
|
sym::Ordering,
|
||||||
"then_with"])));
|
sym::then_with])));
|
||||||
cx.expr_call(span, then_with_path, vec![par_cmp, cx.lambda0(span, subexpr)])
|
cx.expr_call(span, then_with_path, vec![par_cmp, cx.lambda0(span, subexpr)])
|
||||||
},
|
},
|
||||||
|cx, args| {
|
|cx, args| {
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::{kw, 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,
|
||||||
|
@ -47,7 +47,8 @@ fn default_substructure(cx: &mut ExtCtxt<'_>,
|
||||||
trait_span: Span,
|
trait_span: Span,
|
||||||
substr: &Substructure<'_>)
|
substr: &Substructure<'_>)
|
||||||
-> P<Expr> {
|
-> P<Expr> {
|
||||||
let default_ident = cx.std_path(&["default", "Default", "default"]);
|
// Note that `kw::Default` is "default" and `sym::Default` is "Default"!
|
||||||
|
let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]);
|
||||||
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
|
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
|
|
|
@ -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];
|
||||||
|
|
|
@ -6,6 +6,7 @@ use syntax::ast::{Expr, MetaItem, Mutability};
|
||||||
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::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
|
pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
|
||||||
|
@ -60,7 +61,7 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu
|
||||||
};
|
};
|
||||||
let call_hash = |span, thing_expr| {
|
let call_hash = |span, thing_expr| {
|
||||||
let hash_path = {
|
let hash_path = {
|
||||||
let strs = cx.std_path(&["hash", "Hash", "hash"]);
|
let strs = cx.std_path(&[sym::hash, sym::Hash, sym::hash]);
|
||||||
|
|
||||||
cx.expr_path(cx.path_global(span, strs))
|
cx.expr_path(cx.path_global(span, strs))
|
||||||
};
|
};
|
||||||
|
|
|
@ -145,12 +145,12 @@ 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));
|
||||||
}
|
}
|
||||||
let path = cx.std_path(&["intrinsics", intrinsic]);
|
let path = cx.std_path(&[sym::intrinsics, Symbol::intern(intrinsic)]);
|
||||||
let call = cx.expr_call_global(span, path, args);
|
let call = cx.expr_call_global(span, path, args);
|
||||||
|
|
||||||
cx.expr_block(P(ast::Block {
|
cx.expr_block(P(ast::Block {
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
||||||
let lt = cx.lifetime(sp, Ident::with_empty_ctxt(kw::StaticLifetime));
|
let lt = cx.lifetime(sp, Ident::with_empty_ctxt(kw::StaticLifetime));
|
||||||
cx.expr_path(cx.path_all(sp,
|
cx.expr_path(cx.path_all(sp,
|
||||||
true,
|
true,
|
||||||
cx.std_path(&["option", "Option", "None"]),
|
cx.std_path(&[sym::option, sym::Option, sym::None]),
|
||||||
vec![GenericArg::Type(cx.ty_rptr(sp,
|
vec![GenericArg::Type(cx.ty_rptr(sp,
|
||||||
cx.ty_ident(sp,
|
cx.ty_ident(sp,
|
||||||
Ident::with_empty_ctxt(sym::str)),
|
Ident::with_empty_ctxt(sym::str)),
|
||||||
|
@ -37,7 +37,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
||||||
}
|
}
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
cx.expr_call_global(sp,
|
cx.expr_call_global(sp,
|
||||||
cx.std_path(&["option", "Option", "Some"]),
|
cx.std_path(&[sym::option, sym::Option, sym::Some]),
|
||||||
vec![cx.expr_str(sp, Symbol::intern(&s))])
|
vec![cx.expr_str(sp, Symbol::intern(&s))])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -387,7 +387,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec<ast::Ident> {
|
fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec<ast::Ident> {
|
||||||
ecx.std_path(&["fmt", "rt", "v1", s])
|
ecx.std_path(&[sym::fmt, sym::rt, sym::v1, Symbol::intern(s)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_count(&self, c: parse::Count<'_>) -> P<ast::Expr> {
|
fn build_count(&self, c: parse::Count<'_>) -> P<ast::Expr> {
|
||||||
|
@ -644,7 +644,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
("new_v1_formatted", vec![pieces, args_slice, fmt])
|
("new_v1_formatted", vec![pieces, args_slice, fmt])
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = self.ecx.std_path(&["fmt", "Arguments", fn_name]);
|
let path = self.ecx.std_path(&[sym::fmt, sym::Arguments, Symbol::intern(fn_name)]);
|
||||||
self.ecx.expr_call_global(self.macsp, path, fn_args)
|
self.ecx.expr_call_global(self.macsp, path, fn_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,14 +675,14 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Count => {
|
Count => {
|
||||||
let path = ecx.std_path(&["fmt", "ArgumentV1", "from_usize"]);
|
let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::from_usize]);
|
||||||
return ecx.expr_call_global(macsp, path, vec![arg]);
|
return ecx.expr_call_global(macsp, path, vec![arg]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = ecx.std_path(&["fmt", trait_, "fmt"]);
|
let path = ecx.std_path(&[sym::fmt, Symbol::intern(trait_), sym::fmt]);
|
||||||
let format_fn = ecx.path_global(sp, path);
|
let format_fn = ecx.path_global(sp, path);
|
||||||
let path = ecx.std_path(&["fmt", "ArgumentV1", "new"]);
|
let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::new]);
|
||||||
ecx.expr_call_global(macsp, path, vec![arg, ecx.expr_path(format_fn)])
|
ecx.expr_call_global(macsp, path, vec![arg, ecx.expr_path(format_fn)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,10 +9,10 @@ use rustc_data_structures::newtype_index;
|
||||||
use rustc_macros::symbols;
|
use rustc_macros::symbols;
|
||||||
use serialize::{Decodable, Decoder, Encodable, Encoder};
|
use serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::str;
|
|
||||||
use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
|
use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
|
||||||
|
use std::fmt;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::str;
|
||||||
|
|
||||||
use crate::hygiene::SyntaxContext;
|
use crate::hygiene::SyntaxContext;
|
||||||
use crate::{Span, DUMMY_SP, GLOBALS};
|
use crate::{Span, DUMMY_SP, GLOBALS};
|
||||||
|
@ -102,6 +102,9 @@ symbols! {
|
||||||
// Symbols that can be referred to with syntax_pos::sym::*. The symbol is
|
// Symbols that can be referred to with syntax_pos::sym::*. The symbol is
|
||||||
// the stringified identifier unless otherwise specified (e.g.
|
// the stringified identifier unless otherwise specified (e.g.
|
||||||
// `proc_dash_macro` represents "proc-macro").
|
// `proc_dash_macro` represents "proc-macro").
|
||||||
|
//
|
||||||
|
// As well as the symbols listed, there are symbols for the the strings
|
||||||
|
// "0", "1", ..., "9", which are accessible via `sym::integer`.
|
||||||
Symbols {
|
Symbols {
|
||||||
aarch64_target_feature,
|
aarch64_target_feature,
|
||||||
abi,
|
abi,
|
||||||
|
@ -130,8 +133,11 @@ symbols! {
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
allow_internal_unstable_backcompat_hack,
|
allow_internal_unstable_backcompat_hack,
|
||||||
always,
|
always,
|
||||||
|
and,
|
||||||
any,
|
any,
|
||||||
arbitrary_self_types,
|
arbitrary_self_types,
|
||||||
|
Arguments,
|
||||||
|
ArgumentV1,
|
||||||
arm_target_feature,
|
arm_target_feature,
|
||||||
asm,
|
asm,
|
||||||
associated_consts,
|
associated_consts,
|
||||||
|
@ -145,6 +151,8 @@ symbols! {
|
||||||
automatically_derived,
|
automatically_derived,
|
||||||
avx512_target_feature,
|
avx512_target_feature,
|
||||||
await_macro,
|
await_macro,
|
||||||
|
begin_panic,
|
||||||
|
bench,
|
||||||
bin,
|
bin,
|
||||||
bind_by_move_pattern_guards,
|
bind_by_move_pattern_guards,
|
||||||
block,
|
block,
|
||||||
|
@ -163,9 +171,11 @@ symbols! {
|
||||||
cfg_target_thread_local,
|
cfg_target_thread_local,
|
||||||
cfg_target_vendor,
|
cfg_target_vendor,
|
||||||
clone,
|
clone,
|
||||||
|
Clone,
|
||||||
clone_closures,
|
clone_closures,
|
||||||
clone_from,
|
clone_from,
|
||||||
closure_to_fn_coercion,
|
closure_to_fn_coercion,
|
||||||
|
cmp,
|
||||||
cmpxchg16b_target_feature,
|
cmpxchg16b_target_feature,
|
||||||
cold,
|
cold,
|
||||||
compile_error,
|
compile_error,
|
||||||
|
@ -199,11 +209,14 @@ symbols! {
|
||||||
custom_test_frameworks,
|
custom_test_frameworks,
|
||||||
c_variadic,
|
c_variadic,
|
||||||
decl_macro,
|
decl_macro,
|
||||||
|
Default,
|
||||||
default_lib_allocator,
|
default_lib_allocator,
|
||||||
default_type_parameter_fallback,
|
default_type_parameter_fallback,
|
||||||
default_type_params,
|
default_type_params,
|
||||||
deny,
|
deny,
|
||||||
deprecated,
|
deprecated,
|
||||||
|
deref,
|
||||||
|
deref_mut,
|
||||||
derive,
|
derive,
|
||||||
doc,
|
doc,
|
||||||
doc_alias,
|
doc_alias,
|
||||||
|
@ -231,6 +244,7 @@ symbols! {
|
||||||
enable,
|
enable,
|
||||||
err,
|
err,
|
||||||
Err,
|
Err,
|
||||||
|
Equal,
|
||||||
except,
|
except,
|
||||||
exclusive_range_pattern,
|
exclusive_range_pattern,
|
||||||
exhaustive_integer_patterns,
|
exhaustive_integer_patterns,
|
||||||
|
@ -238,6 +252,7 @@ symbols! {
|
||||||
existential_type,
|
existential_type,
|
||||||
expected,
|
expected,
|
||||||
export_name,
|
export_name,
|
||||||
|
expr,
|
||||||
extern_absolute_paths,
|
extern_absolute_paths,
|
||||||
external_doc,
|
external_doc,
|
||||||
extern_crate_item_prelude,
|
extern_crate_item_prelude,
|
||||||
|
@ -250,8 +265,11 @@ symbols! {
|
||||||
f64,
|
f64,
|
||||||
feature,
|
feature,
|
||||||
ffi_returns_twice,
|
ffi_returns_twice,
|
||||||
|
field,
|
||||||
field_init_shorthand,
|
field_init_shorthand,
|
||||||
file,
|
file,
|
||||||
|
fmt,
|
||||||
|
fmt_internals,
|
||||||
fn_must_use,
|
fn_must_use,
|
||||||
forbid,
|
forbid,
|
||||||
format_args_nl,
|
format_args_nl,
|
||||||
|
@ -260,6 +278,7 @@ symbols! {
|
||||||
from_error,
|
from_error,
|
||||||
from_generator,
|
from_generator,
|
||||||
from_ok,
|
from_ok,
|
||||||
|
from_usize,
|
||||||
fundamental,
|
fundamental,
|
||||||
future,
|
future,
|
||||||
Future,
|
Future,
|
||||||
|
@ -270,6 +289,8 @@ symbols! {
|
||||||
global_allocator,
|
global_allocator,
|
||||||
global_asm,
|
global_asm,
|
||||||
globs,
|
globs,
|
||||||
|
hash,
|
||||||
|
Hash,
|
||||||
hexagon_target_feature,
|
hexagon_target_feature,
|
||||||
hidden,
|
hidden,
|
||||||
homogeneous_aggregate,
|
homogeneous_aggregate,
|
||||||
|
@ -291,6 +312,8 @@ symbols! {
|
||||||
impl_header_lifetime_elision,
|
impl_header_lifetime_elision,
|
||||||
impl_trait_in_bindings,
|
impl_trait_in_bindings,
|
||||||
import_shadowing,
|
import_shadowing,
|
||||||
|
index,
|
||||||
|
index_mut,
|
||||||
in_band_lifetimes,
|
in_band_lifetimes,
|
||||||
include,
|
include,
|
||||||
inclusive_range_syntax,
|
inclusive_range_syntax,
|
||||||
|
@ -307,6 +330,7 @@ symbols! {
|
||||||
issue,
|
issue,
|
||||||
issue_5723_bootstrap,
|
issue_5723_bootstrap,
|
||||||
issue_tracker_base_url,
|
issue_tracker_base_url,
|
||||||
|
item,
|
||||||
item_like_imports,
|
item_like_imports,
|
||||||
iter,
|
iter,
|
||||||
Iterator,
|
Iterator,
|
||||||
|
@ -317,6 +341,7 @@ symbols! {
|
||||||
lang,
|
lang,
|
||||||
lang_items,
|
lang_items,
|
||||||
lib,
|
lib,
|
||||||
|
lifetime,
|
||||||
link,
|
link,
|
||||||
linkage,
|
linkage,
|
||||||
link_args,
|
link_args,
|
||||||
|
@ -325,6 +350,7 @@ symbols! {
|
||||||
link_name,
|
link_name,
|
||||||
link_section,
|
link_section,
|
||||||
lint_reasons,
|
lint_reasons,
|
||||||
|
literal,
|
||||||
local_inner_macros,
|
local_inner_macros,
|
||||||
log_syntax,
|
log_syntax,
|
||||||
loop_break_value,
|
loop_break_value,
|
||||||
|
@ -364,6 +390,7 @@ symbols! {
|
||||||
negate_unsigned,
|
negate_unsigned,
|
||||||
never,
|
never,
|
||||||
never_type,
|
never_type,
|
||||||
|
new,
|
||||||
next,
|
next,
|
||||||
__next,
|
__next,
|
||||||
nll,
|
nll,
|
||||||
|
@ -398,14 +425,21 @@ symbols! {
|
||||||
option,
|
option,
|
||||||
Option,
|
Option,
|
||||||
opt_out_copy,
|
opt_out_copy,
|
||||||
|
or,
|
||||||
|
Ord,
|
||||||
|
Ordering,
|
||||||
Output,
|
Output,
|
||||||
overlapping_marker_traits,
|
overlapping_marker_traits,
|
||||||
packed,
|
packed,
|
||||||
|
panic,
|
||||||
panic_handler,
|
panic_handler,
|
||||||
panic_impl,
|
panic_impl,
|
||||||
panic_implementation,
|
panic_implementation,
|
||||||
panic_runtime,
|
panic_runtime,
|
||||||
|
partial_cmp,
|
||||||
|
PartialOrd,
|
||||||
passes,
|
passes,
|
||||||
|
pat,
|
||||||
path,
|
path,
|
||||||
pattern_parentheses,
|
pattern_parentheses,
|
||||||
Pending,
|
Pending,
|
||||||
|
@ -426,6 +460,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,
|
||||||
|
@ -464,6 +499,7 @@ symbols! {
|
||||||
Result,
|
Result,
|
||||||
Return,
|
Return,
|
||||||
rlib,
|
rlib,
|
||||||
|
rt,
|
||||||
rtm_target_feature,
|
rtm_target_feature,
|
||||||
rust,
|
rust,
|
||||||
rust_2015_preview,
|
rust_2015_preview,
|
||||||
|
@ -547,6 +583,7 @@ symbols! {
|
||||||
static_recursion,
|
static_recursion,
|
||||||
std,
|
std,
|
||||||
str,
|
str,
|
||||||
|
stmt,
|
||||||
stmt_expr_attributes,
|
stmt_expr_attributes,
|
||||||
stop_after_dataflow,
|
stop_after_dataflow,
|
||||||
struct_field_attributes,
|
struct_field_attributes,
|
||||||
|
@ -564,8 +601,10 @@ 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,
|
||||||
|
then_with,
|
||||||
thread_local,
|
thread_local,
|
||||||
tool_attributes,
|
tool_attributes,
|
||||||
tool_lints,
|
tool_lints,
|
||||||
|
@ -577,6 +616,7 @@ symbols! {
|
||||||
Try,
|
Try,
|
||||||
try_blocks,
|
try_blocks,
|
||||||
try_trait,
|
try_trait,
|
||||||
|
tt,
|
||||||
tuple_indexing,
|
tuple_indexing,
|
||||||
ty,
|
ty,
|
||||||
type_alias_enum_variants,
|
type_alias_enum_variants,
|
||||||
|
@ -605,12 +645,15 @@ symbols! {
|
||||||
untagged_unions,
|
untagged_unions,
|
||||||
unwind,
|
unwind,
|
||||||
unwind_attributes,
|
unwind_attributes,
|
||||||
|
unwrap_or,
|
||||||
used,
|
used,
|
||||||
use_extern_macros,
|
use_extern_macros,
|
||||||
use_nested_groups,
|
use_nested_groups,
|
||||||
usize,
|
usize,
|
||||||
v1,
|
v1,
|
||||||
val,
|
val,
|
||||||
|
vec,
|
||||||
|
Vec,
|
||||||
vis,
|
vis,
|
||||||
visible_private_types,
|
visible_private_types,
|
||||||
volatile,
|
volatile,
|
||||||
|
@ -935,8 +978,21 @@ pub mod kw {
|
||||||
|
|
||||||
// This module has a very short name because it's used a lot.
|
// This module has a very short name because it's used a lot.
|
||||||
pub mod sym {
|
pub mod sym {
|
||||||
|
use std::convert::TryInto;
|
||||||
use super::Symbol;
|
use super::Symbol;
|
||||||
|
|
||||||
symbols!();
|
symbols!();
|
||||||
|
|
||||||
|
// Get the symbol for an integer. The first few non-negative integers each
|
||||||
|
// have a static symbol and therefore are fast.
|
||||||
|
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
|
||||||
|
if let Result::Ok(idx) = n.try_into() {
|
||||||
|
if let Option::Some(&sym) = digits_array.get(idx) {
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Symbol::intern(&n.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
|
|
Loading…
Add table
Reference in a new issue