diff options
| author | bors <bors@rust-lang.org> | 2019-05-27 06:53:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-27 06:53:53 +0000 |
| commit | ab7cf71d4c6dd1696cb0eb52ad172bce296578cc (patch) | |
| tree | 48c001b66e3a12c491ca5e20b8fb63d303c08636 /src/libsyntax | |
| parent | be10e6277b738df3cc8ac316872227879118cc64 (diff) | |
| parent | 33a3206dc5e7f267617a625d8b31ccc3250cdc1e (diff) | |
| download | rust-ab7cf71d4c6dd1696cb0eb52ad172bce296578cc.tar.gz rust-ab7cf71d4c6dd1696cb0eb52ad172bce296578cc.zip | |
Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=petrochenkov
Avoid more symbol interning r? @petrochenkov
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 38 | ||||
| -rw-r--r-- | src/libsyntax/ext/derive.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 54 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/diagnostics.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/literal.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/std_inject.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 12 |
14 files changed, 99 insertions, 93 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3276f152575..75e83bd9f9c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,7 @@ use crate::parse::token; use crate::print::pprust; use crate::ptr::P; 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::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 { // 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 @@ -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 { format!("{}{}", val, self.ty_to_string()) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index dbec379e769..d72193ffe12 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> { pub fn ident_of(&self, st: &str) -> ast::Ident { 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); 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() } pub fn name_of(&self, st: &str) -> ast::Name { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index ad8fb12deb7..9c0ffc1f6e8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -3,11 +3,11 @@ use crate::attr; use crate::source_map::{dummy_spanned, respan, Spanned}; use crate::ext::base::ExtCtxt; use crate::ptr::P; -use crate::symbol::{Symbol, kw}; +use crate::symbol::{kw, sym, Symbol}; use crate::ThinVec; use rustc_target::spec::abi::Abi; -use syntax_pos::{Pos, Span, DUMMY_SP}; +use syntax_pos::{Pos, Span}; pub trait AstBuilder { // paths @@ -49,7 +49,6 @@ pub trait AstBuilder { ty: 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 typaram(&self, @@ -425,15 +424,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> { 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> { self.ty(span, ast::TyKind::Infer) } @@ -735,7 +725,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::Array(exprs)) } 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()) } 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> { - 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]) } 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); 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); self.expr_call_global( span, - self.std_path(&["rt", "begin_panic"]), + self.std_path(&[sym::rt, sym::begin_panic]), vec![ self.expr_str(span, msg), 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> { - 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]) } 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]) } 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 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 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> { - 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); self.pat_tuple_struct(span, path, vec![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); self.pat_path(span, path) } 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); self.pat_tuple_struct(span, path, vec![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); self.pat_tuple_struct(span, path, vec![pat]) } diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 6e789c4c708..c47224ca0ce 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -58,10 +58,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P call_site: span, def_site: None, format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), - allow_internal_unstable: Some(vec![ - Symbol::intern("rustc_attrs"), - Symbol::intern("structural_match"), - ].into()), + allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()), allow_internal_unsafe: false, local_inner_macros: false, 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)); } 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)); } }); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index fbe052252a1..c2a73b662c6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -938,7 +938,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } BuiltinDerive(func) => { expn_info.allow_internal_unstable = Some(vec![ - Symbol::intern("rustc_attrs"), + sym::rustc_attrs, Symbol::intern("derive_clone_copy"), Symbol::intern("derive_eq"), Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index e55226b8579..7b7cf80760f 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -80,7 +80,7 @@ use crate::parse::{Directory, ParseSess}; use crate::parse::parser::{Parser, PathStyle}; use crate::parse::token::{self, DocComment, Nonterminal, Token}; use crate::print::pprust; -use crate::symbol::kw; +use crate::symbol::{kw, sym, Symbol}; use crate::tokenstream::{DelimSpan, TokenStream}; use errors::FatalError; @@ -598,7 +598,7 @@ fn inner_parse_loop<'root, 'tt>( TokenTree::MetaVarDecl(_, _, id) => { // Built-in nonterminals never start with these tokens, // 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); } } @@ -791,7 +791,7 @@ pub fn parse( let match_cur = item.match_cur; item.push_match( 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.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 /// 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. fn may_be_ident(nt: &token::Nonterminal) -> bool { match *nt { @@ -829,16 +829,16 @@ fn may_begin_with(name: &str, token: &Token) -> bool { } match name { - "expr" => token.can_begin_expr(), - "ty" => token.can_begin_type(), - "ident" => get_macro_ident(token).is_some(), - "literal" => token.can_begin_literal_or_bool(), - "vis" => match *token { + sym::expr => token.can_begin_expr(), + sym::ty => token.can_begin_type(), + sym::ident => get_macro_ident(token).is_some(), + sym::literal => token.can_begin_literal_or_bool(), + sym::vis => match *token { // The follow-set of :vis + "priv" keyword + interpolated Token::Comma | Token::Ident(..) | Token::Interpolated(_) => true, _ => token.can_begin_type(), }, - "block" => match *token { + sym::block => match *token { Token::OpenDelim(token::Brace) => true, Token::Interpolated(ref nt) => match **nt { token::NtItem(_) @@ -852,7 +852,7 @@ fn may_begin_with(name: &str, token: &Token) -> bool { }, _ => false, }, - "path" | "meta" => match *token { + sym::path | sym::meta => match *token { Token::ModSep | Token::Ident(..) => true, Token::Interpolated(ref nt) => match **nt { token::NtPath(_) | token::NtMeta(_) => true, @@ -860,7 +860,7 @@ fn may_begin_with(name: &str, token: &Token) -> bool { }, _ => false, }, - "pat" => match *token { + sym::pat => match *token { Token::Ident(..) | // box, ref, mut, and other identifiers (can stricten) Token::OpenDelim(token::Paren) | // tuple 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), _ => false, }, - "lifetime" => match *token { + sym::lifetime => match *token { Token::Lifetime(_) => true, Token::Interpolated(ref nt) => match **nt { token::NtLifetime(_) | token::NtTT(_) => true, @@ -903,34 +903,34 @@ fn may_begin_with(name: &str, token: &Token) -> bool { /// # Returns /// /// The parsed non-terminal. -fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { - if name == "tt" { +fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> Nonterminal { + if name == sym::tt { return token::NtTT(p.parse_token_tree()); } // check at the beginning and the parser checks after each bump p.process_potential_macro_variable(); match name { - "item" => match panictry!(p.parse_item()) { + sym::item => match panictry!(p.parse_item()) { Some(i) => token::NtItem(i), None => { p.fatal("expected an item keyword").emit(); FatalError.raise(); } }, - "block" => token::NtBlock(panictry!(p.parse_block())), - "stmt" => match panictry!(p.parse_stmt()) { + sym::block => token::NtBlock(panictry!(p.parse_block())), + sym::stmt => match panictry!(p.parse_stmt()) { Some(s) => token::NtStmt(s), None => { p.fatal("expected a statement").emit(); FatalError.raise(); } }, - "pat" => token::NtPat(panictry!(p.parse_pat(None))), - "expr" => token::NtExpr(panictry!(p.parse_expr())), - "literal" => token::NtLiteral(panictry!(p.parse_literal_maybe_minus())), - "ty" => token::NtTy(panictry!(p.parse_ty())), + sym::pat => token::NtPat(panictry!(p.parse_pat(None))), + sym::expr => token::NtExpr(panictry!(p.parse_expr())), + sym::literal => token::NtLiteral(panictry!(p.parse_literal_maybe_minus())), + sym::ty => token::NtTy(panictry!(p.parse_ty())), // 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; p.bump(); 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(); FatalError.raise() } - "path" => token::NtPath(panictry!(p.parse_path(PathStyle::Type))), - "meta" => token::NtMeta(panictry!(p.parse_meta_item())), - "vis" => token::NtVis(panictry!(p.parse_visibility(true))), - "lifetime" => if p.check_lifetime() { + sym::path => token::NtPath(panictry!(p.parse_path(PathStyle::Type))), + sym::meta => token::NtMeta(panictry!(p.parse_meta_item())), + sym::vis => token::NtVis(panictry!(p.parse_visibility(true))), + sym::lifetime => if p.check_lifetime() { token::NtLifetime(p.expect_lifetime().ident) } else { let token_str = pprust::token_to_string(&p.token); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 2debd8f048b..285c88357a6 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -396,7 +396,7 @@ pub fn compile( future this will become a hard error. Please use `allow_internal_unstable(\ 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); diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index 9431b559da5..b3d49524d76 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -8,7 +8,7 @@ use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, Token use crate::print::pprust; use crate::ptr::P; use crate::source_map::Spanned; -use crate::symbol::kw; +use crate::symbol::{kw, sym}; use crate::ThinVec; use crate::util::parser::AssocOp; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; @@ -263,7 +263,7 @@ impl<'a> Parser<'a> { }; self.last_unexpected_token_span = Some(self.span); 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( self.span, "use `&&` instead of `and` for the boolean operator", @@ -271,7 +271,7 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); } - if self.token.is_ident_named("or") { + if self.token.is_ident_named(sym::or) { err.span_suggestion_short( self.span, "use `||` instead of `or` for the boolean operator", diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index deb76d6d70a..a06a84f162a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1,7 +1,7 @@ use crate::ast::{self, Ident}; use crate::parse::ParseSess; use crate::parse::token::{self, Token}; -use crate::symbol::Symbol; +use crate::symbol::{sym, Symbol}; use crate::parse::unescape; use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char}; @@ -754,7 +754,7 @@ impl<'a> StringReader<'a> { } _ => { // just a 0 - return (token::Integer, self.name_from(start_bpos)); + return (token::Integer, sym::integer(0)); } } } else if c.is_digit(10) { diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index 0305b1f59b9..18019a89130 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -171,12 +171,15 @@ impl LitKind { /// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing). pub fn to_lit_token(&self) -> token::Lit { let (kind, symbol, suffix) = match *self { - LitKind::Str(string, ast::StrStyle::Cooked) => { - let escaped = string.as_str().escape_default().to_string(); - (token::Str, Symbol::intern(&escaped), None) + LitKind::Str(symbol, ast::StrStyle::Cooked) => { + // Don't re-intern unless the escaped string is different. + 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)) => { - (token::StrRaw(n), string, None) + LitKind::Str(symbol, ast::StrStyle::Raw(n)) => { + (token::StrRaw(n), symbol, None) } LitKind::ByteStr(ref bytes) => { let string = bytes.iter().cloned().flat_map(ascii::escape_default) @@ -193,14 +196,14 @@ impl LitKind { } LitKind::Int(n, ty) => { let suffix = match ty { - ast::LitIntType::Unsigned(ty) => Some(Symbol::intern(ty.ty_to_string())), - ast::LitIntType::Signed(ty) => Some(Symbol::intern(ty.ty_to_string())), + ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()), + ast::LitIntType::Signed(ty) => Some(ty.to_symbol()), ast::LitIntType::Unsuffixed => None, }; - (token::Integer, Symbol::intern(&n.to_string()), suffix) + (token::Integer, sym::integer(n), suffix) } LitKind::Float(symbol, ty) => { - (token::Float, symbol, Some(Symbol::intern(ty.ty_to_string()))) + (token::Float, symbol, Some(ty.to_symbol())) } LitKind::FloatUnsuffixed(symbol) => { (token::Float, symbol, None) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6c29437362c..07efeaa4cf2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2759,7 +2759,7 @@ impl<'a> Parser<'a> { let (span, e) = self.interpolated_or_expr_span(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, // but as `rustc`-the-compiler, we can issue clever diagnostics // for confused users who really want to say `!` @@ -4592,7 +4592,7 @@ impl<'a> Parser<'a> { let do_not_suggest_help = 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( self.span, "use `&&` instead of `and` for the boolean operator", @@ -4600,7 +4600,7 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); } - if self.token.is_ident_named("or") { + if self.token.is_ident_named(sym::or) { e.span_suggestion_short( self.span, "use `||` instead of `or` for the boolean operator", @@ -5787,7 +5787,7 @@ impl<'a> Parser<'a> { VisibilityKind::Inherited => {} _ => { 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, }; let mut err = if is_macro_rules { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index e5361b2db4e..47185df8d61 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -391,9 +391,9 @@ impl Token { /// Returns `true` if the token is a identifier whose name is the given /// string slice. - crate fn is_ident_named(&self, name: &str) -> bool { + crate fn is_ident_named(&self, name: Symbol) -> bool { match self.ident() { - Some((ident, _)) => ident.as_str() == name, + Some((ident, _)) => ident.name == name, None => false } } diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 398705857bb..eea94f0d194 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -20,9 +20,7 @@ fn ignored_span(sp: Span, edition: Edition) -> Span { call_site: DUMMY_SP, def_site: None, format: MacroAttribute(Symbol::intern("std_inject")), - allow_internal_unstable: Some(vec![ - Symbol::intern("prelude_import"), - ].into()), + allow_internal_unstable: Some(vec![sym::prelude_import].into()), allow_internal_unsafe: false, local_inner_macros: false, edition, @@ -98,7 +96,7 @@ pub fn maybe_inject_crates_ref( krate.module.items.insert(0, P(ast::Item { attrs: vec![ast::Attribute { 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(), id: attr::mk_attr_id(), is_sugared_doc: false, diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index d1e11da4e7c..1998ec19f13 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -283,12 +283,8 @@ fn generate_test_harness(sess: &ParseSess, mark.set_expn_info(ExpnInfo { call_site: DUMMY_SP, def_site: None, - format: MacroAttribute(Symbol::intern("test_case")), - allow_internal_unstable: Some(vec![ - Symbol::intern("main"), - Symbol::intern("test"), - Symbol::intern("rustc_attrs"), - ].into()), + format: MacroAttribute(sym::test_case), + allow_internal_unstable: Some(vec![sym::main, sym::test, sym::rustc_attrs].into()), allow_internal_unsafe: false, local_inner_macros: false, 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); // #![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); // extern crate test as test_gensym let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp, test_id, vec![], - ast::ItemKind::ExternCrate(Some(Symbol::intern("test"))) + ast::ItemKind::ExternCrate(Some(sym::test)) )); // pub fn main() { ... } |
