diff options
| -rw-r--r-- | src/doc/reference.md | 12 | ||||
| -rw-r--r-- | src/etc/vim/syntax/rust.vim | 2 | ||||
| -rw-r--r-- | src/librustc_back/svh.rs | 14 | ||||
| -rw-r--r-- | src/librustc_driver/pretty.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/show_span.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-keyword.rs | 15 |
12 files changed, 55 insertions, 39 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index d7930285260..e2134cdebef 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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 diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 5588152a244..270459e8880 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -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 diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index 2ae88aa4476..86bd74d3f85 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -327,11 +327,11 @@ mod svh_visitor { 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 @@ mod svh_visitor { // 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 @@ mod svh_visitor { // 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); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index d972229e7c7..61fd7d16ab7 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -484,8 +484,8 @@ impl fold::Folder for ReplaceBodyWithLoop { // 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) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d3f2e0ea095..8decedf289a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -986,8 +986,8 @@ impl<'a> Folder for IdentRenamer<'a> { 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 @@ impl<'a> Folder for PatIdentRenamer<'a> { _ => 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"); } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e41fef4e778..28265b8e7c2 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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") { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6b5d333ef8f..aa4b04b2879 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -194,13 +194,13 @@ pub trait Folder : Sized { 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 @@ mod test { 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) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5539abb16b4..24011df7acb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3881,13 +3881,13 @@ impl<'a> Parser<'a> { &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 @@ impl<'a> Parser<'a> { _ => { 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( diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a653190cffd..094aacf3207 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -574,6 +574,7 @@ declare_special_idents_and_keywords! { (56, Abstract, "abstract"); (57, Final, "final"); (58, Override, "override"); + (59, Macro, "macro"); } } diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 354ba854b10..e7c9101ebc6 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -28,8 +28,8 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> { 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); } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 054a288a69e..888c0251d76 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -115,13 +115,13 @@ pub trait Visitor<'v> : Sized { 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) } diff --git a/src/test/compile-fail/macro-keyword.rs b/src/test/compile-fail/macro-keyword.rs new file mode 100644 index 00000000000..9d4ec9c176c --- /dev/null +++ b/src/test/compile-fail/macro-keyword.rs @@ -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() { +} |
