Skip to content

Commit 77958d5

Browse files
committed
Forbid user-defined macros named "macro_rules".
1 parent 5fc14c1 commit 77958d5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/librustc_plugin/registry.rs

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ impl<'a> Registry<'a> {
101101
///
102102
/// This is the most general hook into `libsyntax`'s expansion behavior.
103103
pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
104+
if name.as_str() == "macro_rules" {
105+
panic!("user-defined macros may not be named `macro_rules`");
106+
}
104107
self.syntax_exts.push((name, match extension {
105108
NormalTT(ext, _, allow_internal_unstable) => {
106109
NormalTT(ext, Some(self.krate_span), allow_internal_unstable)

src/librustc_resolve/macros.rs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ impl<'a> base::Resolver for Resolver<'a> {
5353
}
5454

5555
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) {
56+
if &def.ident.name.as_str() == "macro_rules" {
57+
self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`");
58+
}
5659
if def.use_locally {
5760
let ext = macro_rules::compile(&self.session.parse_sess, &def);
5861
self.add_ext(scope, def.ident, Rc::new(ext));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2016 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+
macro_rules! macro_rules { () => {} } //~ ERROR user-defined macros may not be named `macro_rules`

0 commit comments

Comments
 (0)