Skip to content

Commit c9f0ff3

Browse files
author
Keegan McAllister
committed
Reserve the keyword 'macro'
1 parent aa69cbd commit c9f0ff3

File tree

12 files changed

+55
-39
lines changed

12 files changed

+55
-39
lines changed

src/doc/reference.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ grammar as double-quoted strings. Other tokens have exact rules given.
193193
| break | const | continue | crate | do |
194194
| else | enum | extern | false | final |
195195
| fn | for | if | impl | in |
196-
| let | loop | match | mod | move |
197-
| mut | offsetof | override | priv | pub |
198-
| pure | ref | return | sizeof | static |
199-
| self | struct | super | true | trait |
200-
| type | typeof | unsafe | unsized | use |
201-
| virtual | where | while | yield |
196+
| let | loop | macro | match | mod |
197+
| move | mut | offsetof | override | priv |
198+
| pub | pure | ref | return | sizeof |
199+
| static | self | struct | super | true |
200+
| trait | type | typeof | unsafe | unsized |
201+
| use | virtual | where | while | yield |
202202

203203

204204
Each of these keywords has special meaning in its grammar, and all of them are

src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ syn match rustMacroRepeatCount ".\?[*+]" contained
5656
syn match rustMacroVariable "$\w\+"
5757

5858
" Reserved (but not yet used) keywords {{{2
59-
syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override
59+
syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override macro
6060

6161
" Built-in types {{{2
6262
syn keyword rustType int uint float char bool u8 u16 u32 u64 f32

src/librustc_back/svh.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ mod svh_visitor {
327327

328328
impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
329329

330-
fn visit_mac(&mut self, macro: &Mac) {
330+
fn visit_mac(&mut self, mac: &Mac) {
331331
// macro invocations, namely macro_rules definitions,
332332
// *can* appear as items, even in the expanded crate AST.
333333

334-
if macro_name(macro).get() == "macro_rules" {
334+
if macro_name(mac).get() == "macro_rules" {
335335
// Pretty-printing definition to a string strips out
336336
// surface artifacts (currently), such as the span
337337
// information, yielding a content-based hash.
@@ -341,22 +341,22 @@ mod svh_visitor {
341341
// trees might be faster. Implementing this is far
342342
// easier in short term.
343343
let macro_defn_as_string = pprust::to_string(|pp_state| {
344-
pp_state.print_mac(macro, token::Paren)
344+
pp_state.print_mac(mac, token::Paren)
345345
});
346346
macro_defn_as_string.hash(self.st);
347347
} else {
348348
// It is not possible to observe any kind of macro
349349
// invocation at this stage except `macro_rules!`.
350350
panic!("reached macro somehow: {}",
351351
pprust::to_string(|pp_state| {
352-
pp_state.print_mac(macro, token::Paren)
352+
pp_state.print_mac(mac, token::Paren)
353353
}));
354354
}
355355

356-
visit::walk_mac(self, macro);
356+
visit::walk_mac(self, mac);
357357

358-
fn macro_name(macro: &Mac) -> token::InternedString {
359-
match &macro.node {
358+
fn macro_name(mac: &Mac) -> token::InternedString {
359+
match &mac.node {
360360
&MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => {
361361
let s = path.segments[];
362362
assert_eq!(s.len(), 1);

src/librustc_driver/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ impl fold::Folder for ReplaceBodyWithLoop {
484484

485485
// in general the pretty printer processes unexpanded code, so
486486
// we override the default `fold_mac` method which panics.
487-
fn fold_mac(&mut self, _macro: ast::Mac) -> ast::Mac {
488-
fold::noop_fold_mac(_macro, self)
487+
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
488+
fold::noop_fold_mac(mac, self)
489489
}
490490
}
491491

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,8 @@ impl<'a> Folder for IdentRenamer<'a> {
986986
ctxt: mtwt::apply_renames(self.renames, id.ctxt),
987987
}
988988
}
989-
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
990-
fold::noop_fold_mac(macro, self)
989+
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
990+
fold::noop_fold_mac(mac, self)
991991
}
992992
}
993993

@@ -1023,8 +1023,8 @@ impl<'a> Folder for PatIdentRenamer<'a> {
10231023
_ => unreachable!()
10241024
})
10251025
}
1026-
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
1027-
fold::noop_fold_mac(macro, self)
1026+
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
1027+
fold::noop_fold_mac(mac, self)
10281028
}
10291029
}
10301030

@@ -1286,8 +1286,8 @@ struct MacroExterminator<'a>{
12861286
}
12871287

12881288
impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
1289-
fn visit_mac(&mut self, macro: &ast::Mac) {
1290-
self.sess.span_diagnostic.span_bug(macro.span,
1289+
fn visit_mac(&mut self, mac: &ast::Mac) {
1290+
self.sess.span_diagnostic.span_bug(mac.span,
12911291
"macro exterminator: expected AST \
12921292
with no macro invocations");
12931293
}

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ struct MacroVisitor<'a> {
165165
}
166166

167167
impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
168-
fn visit_mac(&mut self, macro: &ast::Mac) {
169-
let ast::MacInvocTT(ref path, _, _) = macro.node;
168+
fn visit_mac(&mut self, mac: &ast::Mac) {
169+
let ast::MacInvocTT(ref path, _, _) = mac.node;
170170
let id = path.segments.last().unwrap().identifier;
171171

172172
if id == token::str_to_ident("macro_rules") {

src/libsyntax/fold.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ pub trait Folder : Sized {
194194
noop_fold_local(l, self)
195195
}
196196

197-
fn fold_mac(&mut self, _macro: Mac) -> Mac {
197+
fn fold_mac(&mut self, _mac: Mac) -> Mac {
198198
panic!("fold_mac disabled by default");
199199
// NB: see note about macros above.
200200
// if you really want a folder that
201201
// works on macros, use this
202202
// definition in your trait impl:
203-
// fold::noop_fold_mac(_macro, self)
203+
// fold::noop_fold_mac(_mac, self)
204204
}
205205

206206
fn fold_explicit_self(&mut self, es: ExplicitSelf) -> ExplicitSelf {
@@ -1487,8 +1487,8 @@ mod test {
14871487
fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident {
14881488
token::str_to_ident("zz")
14891489
}
1490-
fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac {
1491-
fold::noop_fold_mac(macro, self)
1490+
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
1491+
fold::noop_fold_mac(mac, self)
14921492
}
14931493
}
14941494

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,13 +3881,13 @@ impl<'a> Parser<'a> {
38813881
&mut stmts,
38823882
&mut expr);
38833883
}
3884-
StmtMac(macro, MacStmtWithoutBraces) => {
3884+
StmtMac(mac, MacStmtWithoutBraces) => {
38853885
// statement macro without braces; might be an
38863886
// expr depending on whether a semicolon follows
38873887
match self.token {
38883888
token::Semi => {
38893889
stmts.push(P(Spanned {
3890-
node: StmtMac(macro,
3890+
node: StmtMac(mac,
38913891
MacStmtWithSemicolon),
38923892
span: span,
38933893
}));
@@ -3896,7 +3896,7 @@ impl<'a> Parser<'a> {
38963896
_ => {
38973897
let e = self.mk_mac_expr(span.lo,
38983898
span.hi,
3899-
macro.and_then(|m| m.node));
3899+
mac.and_then(|m| m.node));
39003900
let e =
39013901
self.parse_dot_or_call_expr_with(e);
39023902
self.handle_expression_like_statement(

src/libsyntax/parse/token.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ declare_special_idents_and_keywords! {
574574
(56, Abstract, "abstract");
575575
(57, Final, "final");
576576
(58, Override, "override");
577+
(59, Macro, "macro");
577578
}
578579
}
579580

src/libsyntax/show_span.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
2828
visit::walk_expr(self, e);
2929
}
3030

31-
fn visit_mac(&mut self, macro: &ast::Mac) {
32-
visit::walk_mac(self, macro);
31+
fn visit_mac(&mut self, mac: &ast::Mac) {
32+
visit::walk_mac(self, mac);
3333
}
3434
}
3535

src/libsyntax/visit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ pub trait Visitor<'v> : Sized {
115115
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
116116
walk_explicit_self(self, es)
117117
}
118-
fn visit_mac(&mut self, _macro: &'v Mac) {
118+
fn visit_mac(&mut self, _mac: &'v Mac) {
119119
panic!("visit_mac disabled by default");
120120
// NB: see note about macros above.
121121
// if you really want a visitor that
122122
// works on macros, use this
123123
// definition in your trait impl:
124-
// visit::walk_mac(self, _macro)
124+
// visit::walk_mac(self, _mac)
125125
}
126126
fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
127127
walk_path(self, path)
@@ -334,7 +334,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
334334
visitor.visit_trait_item(method)
335335
}
336336
}
337-
ItemMac(ref macro) => visitor.visit_mac(macro),
337+
ItemMac(ref mac) => visitor.visit_mac(mac),
338338
}
339339
for attr in item.attrs.iter() {
340340
visitor.visit_attribute(attr);
@@ -546,7 +546,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
546546
visitor.visit_pat(&**postpattern)
547547
}
548548
}
549-
PatMac(ref macro) => visitor.visit_mac(macro),
549+
PatMac(ref mac) => visitor.visit_mac(mac),
550550
}
551551
}
552552

@@ -746,7 +746,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
746746
StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
747747
visitor.visit_expr(&**expression)
748748
}
749-
StmtMac(ref macro, _) => visitor.visit_mac(&**macro),
749+
StmtMac(ref mac, _) => visitor.visit_mac(&**mac),
750750
}
751751
}
752752

@@ -893,7 +893,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
893893
ExprRet(ref optional_expression) => {
894894
walk_expr_opt(visitor, optional_expression)
895895
}
896-
ExprMac(ref macro) => visitor.visit_mac(macro),
896+
ExprMac(ref mac) => visitor.visit_mac(mac),
897897
ExprParen(ref subexpression) => {
898898
visitor.visit_expr(&**subexpression)
899899
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn macro() { //~ ERROR `macro` is a reserved keyword
12+
}
13+
14+
pub fn main() {
15+
}

0 commit comments

Comments
 (0)