Skip to content

Commit

Permalink
Rollup merge of rust-lang#69186 - petrochenkov:kwrules, r=Centril
Browse files Browse the repository at this point in the history
[tiny] parser: `macro_rules` is a weak keyword

r? @Centril
  • Loading branch information
JohnTitor authored Feb 16, 2020
2 parents fbd42a7 + dcad07a commit f8d7282
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/librustc_expand/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use crate::mbe::{KleeneToken, TokenTree};
use rustc_data_structures::fx::FxHashMap;
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
use rustc_session::parse::ParseSess;
use rustc_span::symbol::{kw, sym};
use rustc_span::symbol::kw;
use rustc_span::{symbol::Ident, MultiSpan, Span};
use syntax::ast::NodeId;
use syntax::token::{DelimToken, Token, TokenKind};
Expand Down Expand Up @@ -392,7 +392,7 @@ fn check_nested_occurrences(
NestedMacroState::Empty,
&TokenTree::Token(Token { kind: TokenKind::Ident(name, false), .. }),
) => {
if name == sym::macro_rules {
if name == kw::MacroRules {
state = NestedMacroState::MacroRules;
} else if name == kw::Macro {
state = NestedMacroState::Macro;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn string_to_tts_macro() {

match tts {
[TokenTree::Token(Token { kind: token::Ident(name_macro_rules, false), .. }), TokenTree::Token(Token { kind: token::Not, .. }), TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. }), TokenTree::Delimited(_, macro_delim, macro_tts)]
if name_macro_rules == &sym::macro_rules && name_zip.as_str() == "zip" =>
if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" =>
{
let tts = &macro_tts.trees().collect::<Vec<_>>();
match &tts[..] {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,14 +1343,14 @@ impl<'a> Parser<'a> {

/// Is this unambiguously the start of a `macro_rules! foo` item defnition?
fn is_macro_rules_item(&mut self) -> bool {
self.check_keyword(sym::macro_rules)
self.check_keyword(kw::MacroRules)
&& self.look_ahead(1, |t| *t == token::Not)
&& self.look_ahead(2, |t| t.is_ident())
}

/// Parses a legacy `macro_rules! foo { ... }` declarative macro.
fn parse_item_macro_rules(&mut self, vis: &Visibility) -> PResult<'a, ItemInfo> {
self.expect_keyword(sym::macro_rules)?; // `macro_rules`
self.expect_keyword(kw::MacroRules)?; // `macro_rules`
self.expect(&token::Not)?; // `!`

let ident = self.parse_ident()?;
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ symbols! {
Auto: "auto",
Catch: "catch",
Default: "default",
MacroRules: "macro_rules",
Raw: "raw",
Union: "union",
}
Expand Down Expand Up @@ -429,7 +430,6 @@ symbols! {
macro_lifetime_matcher,
macro_literal_matcher,
macro_reexport,
macro_rules,
macros_in_extern,
macro_use,
macro_vis_matcher,
Expand Down Expand Up @@ -1071,6 +1071,9 @@ pub mod sym {

symbols!();

// Used from a macro in `librustc_feature/accepted.rs`
pub use super::kw::MacroRules as macro_rules;

// 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 {
Expand Down

0 comments on commit f8d7282

Please sign in to comment.