mirror of
https://github.com/rust-lang/rust
synced 2024-10-01 06:14:33 +00:00
Reserve the keyword 'macro'
This commit is contained in:
parent
aa69cbde82
commit
c9f0ff3813
|
@ -193,12 +193,12 @@ grammar as double-quoted strings. Other tokens have exact rules given.
|
|||
| break | const | continue | crate | do |
|
||||
| else | enum | extern | false | final |
|
||||
| fn | for | if | impl | in |
|
||||
| let | loop | match | mod | move |
|
||||
| mut | offsetof | override | priv | pub |
|
||||
| pure | ref | return | sizeof | static |
|
||||
| self | struct | super | true | trait |
|
||||
| type | typeof | unsafe | unsized | use |
|
||||
| virtual | where | while | yield |
|
||||
| let | loop | macro | match | mod |
|
||||
| move | mut | offsetof | override | priv |
|
||||
| pub | pure | ref | return | sizeof |
|
||||
| static | self | struct | super | true |
|
||||
| trait | type | typeof | unsafe | unsized |
|
||||
| use | virtual | where | while | yield |
|
||||
|
||||
|
||||
Each of these keywords has special meaning in its grammar, and all of them are
|
||||
|
|
|
@ -56,7 +56,7 @@ syn match rustMacroRepeatCount ".\?[*+]" contained
|
|||
syn match rustMacroVariable "$\w\+"
|
||||
|
||||
" Reserved (but not yet used) keywords {{{2
|
||||
syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override
|
||||
syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override macro
|
||||
|
||||
" Built-in types {{{2
|
||||
syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
|
||||
|
|
|
@ -327,11 +327,11 @@ fn content<K:InternKey>(k: K) -> token::InternedString { k.get_content() }
|
|||
|
||||
impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
|
||||
|
||||
fn visit_mac(&mut self, macro: &Mac) {
|
||||
fn visit_mac(&mut self, mac: &Mac) {
|
||||
// macro invocations, namely macro_rules definitions,
|
||||
// *can* appear as items, even in the expanded crate AST.
|
||||
|
||||
if macro_name(macro).get() == "macro_rules" {
|
||||
if macro_name(mac).get() == "macro_rules" {
|
||||
// Pretty-printing definition to a string strips out
|
||||
// surface artifacts (currently), such as the span
|
||||
// information, yielding a content-based hash.
|
||||
|
@ -341,7 +341,7 @@ fn visit_mac(&mut self, macro: &Mac) {
|
|||
// trees might be faster. Implementing this is far
|
||||
// easier in short term.
|
||||
let macro_defn_as_string = pprust::to_string(|pp_state| {
|
||||
pp_state.print_mac(macro, token::Paren)
|
||||
pp_state.print_mac(mac, token::Paren)
|
||||
});
|
||||
macro_defn_as_string.hash(self.st);
|
||||
} else {
|
||||
|
@ -349,14 +349,14 @@ fn visit_mac(&mut self, macro: &Mac) {
|
|||
// invocation at this stage except `macro_rules!`.
|
||||
panic!("reached macro somehow: {}",
|
||||
pprust::to_string(|pp_state| {
|
||||
pp_state.print_mac(macro, token::Paren)
|
||||
pp_state.print_mac(mac, token::Paren)
|
||||
}));
|
||||
}
|
||||
|
||||
visit::walk_mac(self, macro);
|
||||
visit::walk_mac(self, mac);
|
||||
|
||||
fn macro_name(macro: &Mac) -> token::InternedString {
|
||||
match ¯o.node {
|
||||
fn macro_name(mac: &Mac) -> token::InternedString {
|
||||
match &mac.node {
|
||||
&MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => {
|
||||
let s = path.segments[];
|
||||
assert_eq!(s.len(), 1);
|
||||
|
|
|
@ -484,8 +484,8 @@ fn expr_to_block(rules: ast::BlockCheckMode,
|
|||
|
||||
// in general the pretty printer processes unexpanded code, so
|
||||
// we override the default `fold_mac` method which panics.
|
||||
fn fold_mac(&mut self, _macro: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(_macro, self)
|
||||
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(mac, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -986,8 +986,8 @@ fn fold_ident(&mut self, id: Ident) -> Ident {
|
|||
ctxt: mtwt::apply_renames(self.renames, id.ctxt),
|
||||
}
|
||||
}
|
||||
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(macro, self)
|
||||
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(mac, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1023,8 +1023,8 @@ fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
|
|||
_ => unreachable!()
|
||||
})
|
||||
}
|
||||
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(macro, self)
|
||||
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(mac, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1286,8 +1286,8 @@ struct MacroExterminator<'a>{
|
|||
}
|
||||
|
||||
impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
|
||||
fn visit_mac(&mut self, macro: &ast::Mac) {
|
||||
self.sess.span_diagnostic.span_bug(macro.span,
|
||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
||||
self.sess.span_diagnostic.span_bug(mac.span,
|
||||
"macro exterminator: expected AST \
|
||||
with no macro invocations");
|
||||
}
|
||||
|
|
|
@ -165,8 +165,8 @@ struct MacroVisitor<'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
|
||||
fn visit_mac(&mut self, macro: &ast::Mac) {
|
||||
let ast::MacInvocTT(ref path, _, _) = macro.node;
|
||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
||||
let ast::MacInvocTT(ref path, _, _) = mac.node;
|
||||
let id = path.segments.last().unwrap().identifier;
|
||||
|
||||
if id == token::str_to_ident("macro_rules") {
|
||||
|
|
|
@ -194,13 +194,13 @@ fn fold_local(&mut self, l: P<Local>) -> P<Local> {
|
|||
noop_fold_local(l, self)
|
||||
}
|
||||
|
||||
fn fold_mac(&mut self, _macro: Mac) -> Mac {
|
||||
fn fold_mac(&mut self, _mac: Mac) -> Mac {
|
||||
panic!("fold_mac disabled by default");
|
||||
// NB: see note about macros above.
|
||||
// if you really want a folder that
|
||||
// works on macros, use this
|
||||
// definition in your trait impl:
|
||||
// fold::noop_fold_mac(_macro, self)
|
||||
// fold::noop_fold_mac(_mac, self)
|
||||
}
|
||||
|
||||
fn fold_explicit_self(&mut self, es: ExplicitSelf) -> ExplicitSelf {
|
||||
|
@ -1487,8 +1487,8 @@ impl Folder for ToZzIdentFolder {
|
|||
fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident {
|
||||
token::str_to_ident("zz")
|
||||
}
|
||||
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(macro, self)
|
||||
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||
fold::noop_fold_mac(mac, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3881,13 +3881,13 @@ fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
|
|||
&mut stmts,
|
||||
&mut expr);
|
||||
}
|
||||
StmtMac(macro, MacStmtWithoutBraces) => {
|
||||
StmtMac(mac, MacStmtWithoutBraces) => {
|
||||
// statement macro without braces; might be an
|
||||
// expr depending on whether a semicolon follows
|
||||
match self.token {
|
||||
token::Semi => {
|
||||
stmts.push(P(Spanned {
|
||||
node: StmtMac(macro,
|
||||
node: StmtMac(mac,
|
||||
MacStmtWithSemicolon),
|
||||
span: span,
|
||||
}));
|
||||
|
@ -3896,7 +3896,7 @@ fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
|
|||
_ => {
|
||||
let e = self.mk_mac_expr(span.lo,
|
||||
span.hi,
|
||||
macro.and_then(|m| m.node));
|
||||
mac.and_then(|m| m.node));
|
||||
let e =
|
||||
self.parse_dot_or_call_expr_with(e);
|
||||
self.handle_expression_like_statement(
|
||||
|
|
|
@ -574,6 +574,7 @@ pub mod keywords {
|
|||
(56, Abstract, "abstract");
|
||||
(57, Final, "final");
|
||||
(58, Override, "override");
|
||||
(59, Macro, "macro");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ fn visit_expr(&mut self, e: &ast::Expr) {
|
|||
visit::walk_expr(self, e);
|
||||
}
|
||||
|
||||
fn visit_mac(&mut self, macro: &ast::Mac) {
|
||||
visit::walk_mac(self, macro);
|
||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
||||
visit::walk_mac(self, mac);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,13 +115,13 @@ fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
|
|||
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
|
||||
walk_explicit_self(self, es)
|
||||
}
|
||||
fn visit_mac(&mut self, _macro: &'v Mac) {
|
||||
fn visit_mac(&mut self, _mac: &'v Mac) {
|
||||
panic!("visit_mac disabled by default");
|
||||
// NB: see note about macros above.
|
||||
// if you really want a visitor that
|
||||
// works on macros, use this
|
||||
// definition in your trait impl:
|
||||
// visit::walk_mac(self, _macro)
|
||||
// visit::walk_mac(self, _mac)
|
||||
}
|
||||
fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
|
||||
walk_path(self, path)
|
||||
|
@ -334,7 +334,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
|||
visitor.visit_trait_item(method)
|
||||
}
|
||||
}
|
||||
ItemMac(ref macro) => visitor.visit_mac(macro),
|
||||
ItemMac(ref mac) => visitor.visit_mac(mac),
|
||||
}
|
||||
for attr in item.attrs.iter() {
|
||||
visitor.visit_attribute(attr);
|
||||
|
@ -546,7 +546,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
|||
visitor.visit_pat(&**postpattern)
|
||||
}
|
||||
}
|
||||
PatMac(ref macro) => visitor.visit_mac(macro),
|
||||
PatMac(ref mac) => visitor.visit_mac(mac),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -746,7 +746,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
|
|||
StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
|
||||
visitor.visit_expr(&**expression)
|
||||
}
|
||||
StmtMac(ref macro, _) => visitor.visit_mac(&**macro),
|
||||
StmtMac(ref mac, _) => visitor.visit_mac(&**mac),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -893,7 +893,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
|||
ExprRet(ref optional_expression) => {
|
||||
walk_expr_opt(visitor, optional_expression)
|
||||
}
|
||||
ExprMac(ref macro) => visitor.visit_mac(macro),
|
||||
ExprMac(ref mac) => visitor.visit_mac(mac),
|
||||
ExprParen(ref subexpression) => {
|
||||
visitor.visit_expr(&**subexpression)
|
||||
}
|
||||
|
|
15
src/test/compile-fail/macro-keyword.rs
Normal file
15
src/test/compile-fail/macro-keyword.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn macro() { //~ ERROR `macro` is a reserved keyword
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
}
|
Loading…
Reference in a new issue