mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
parser: macro_rules
is a weak keyword
This commit is contained in:
parent
19288ddfd6
commit
dcad07af8a
@ -109,7 +109,7 @@ use crate::mbe::{KleeneToken, TokenTree};
|
|||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
|
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::symbol::{kw, sym};
|
use rustc_span::symbol::kw;
|
||||||
use rustc_span::{symbol::Ident, MultiSpan, Span};
|
use rustc_span::{symbol::Ident, MultiSpan, Span};
|
||||||
use syntax::ast::NodeId;
|
use syntax::ast::NodeId;
|
||||||
use syntax::token::{DelimToken, Token, TokenKind};
|
use syntax::token::{DelimToken, Token, TokenKind};
|
||||||
@ -392,7 +392,7 @@ fn check_nested_occurrences(
|
|||||||
NestedMacroState::Empty,
|
NestedMacroState::Empty,
|
||||||
&TokenTree::Token(Token { kind: TokenKind::Ident(name, false), .. }),
|
&TokenTree::Token(Token { kind: TokenKind::Ident(name, false), .. }),
|
||||||
) => {
|
) => {
|
||||||
if name == sym::macro_rules {
|
if name == kw::MacroRules {
|
||||||
state = NestedMacroState::MacroRules;
|
state = NestedMacroState::MacroRules;
|
||||||
} else if name == kw::Macro {
|
} else if name == kw::Macro {
|
||||||
state = NestedMacroState::Macro;
|
state = NestedMacroState::Macro;
|
||||||
|
@ -65,7 +65,7 @@ fn string_to_tts_macro() {
|
|||||||
|
|
||||||
match tts {
|
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)]
|
[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 = ¯o_tts.trees().collect::<Vec<_>>();
|
let tts = ¯o_tts.trees().collect::<Vec<_>>();
|
||||||
match &tts[..] {
|
match &tts[..] {
|
||||||
|
@ -1343,14 +1343,14 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
/// Is this unambiguously the start of a `macro_rules! foo` item defnition?
|
/// Is this unambiguously the start of a `macro_rules! foo` item defnition?
|
||||||
fn is_macro_rules_item(&mut self) -> bool {
|
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(1, |t| *t == token::Not)
|
||||||
&& self.look_ahead(2, |t| t.is_ident())
|
&& self.look_ahead(2, |t| t.is_ident())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a legacy `macro_rules! foo { ... }` declarative macro.
|
/// Parses a legacy `macro_rules! foo { ... }` declarative macro.
|
||||||
fn parse_item_macro_rules(&mut self, vis: &Visibility) -> PResult<'a, ItemInfo> {
|
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)?; // `!`
|
self.expect(&token::Not)?; // `!`
|
||||||
|
|
||||||
let ident = self.parse_ident()?;
|
let ident = self.parse_ident()?;
|
||||||
|
@ -97,6 +97,7 @@ symbols! {
|
|||||||
Auto: "auto",
|
Auto: "auto",
|
||||||
Catch: "catch",
|
Catch: "catch",
|
||||||
Default: "default",
|
Default: "default",
|
||||||
|
MacroRules: "macro_rules",
|
||||||
Raw: "raw",
|
Raw: "raw",
|
||||||
Union: "union",
|
Union: "union",
|
||||||
}
|
}
|
||||||
@ -429,7 +430,6 @@ symbols! {
|
|||||||
macro_lifetime_matcher,
|
macro_lifetime_matcher,
|
||||||
macro_literal_matcher,
|
macro_literal_matcher,
|
||||||
macro_reexport,
|
macro_reexport,
|
||||||
macro_rules,
|
|
||||||
macros_in_extern,
|
macros_in_extern,
|
||||||
macro_use,
|
macro_use,
|
||||||
macro_vis_matcher,
|
macro_vis_matcher,
|
||||||
@ -1071,6 +1071,9 @@ pub mod sym {
|
|||||||
|
|
||||||
symbols!();
|
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
|
// Get the symbol for an integer. The first few non-negative integers each
|
||||||
// have a static symbol and therefore are fast.
|
// have a static symbol and therefore are fast.
|
||||||
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
|
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
|
||||||
|
Loading…
Reference in New Issue
Block a user