diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index 7b048c0670d5a..9c74a644c3d9d 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -101,6 +101,9 @@ impl<'a> Registry<'a> { /// /// This is the most general hook into `libsyntax`'s expansion behavior. pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) { + if name.as_str() == "macro_rules" { + panic!("user-defined macros may not be named `macro_rules`"); + } self.syntax_exts.push((name, match extension { NormalTT(ext, _, allow_internal_unstable) => { NormalTT(ext, Some(self.krate_span), allow_internal_unstable) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 37cb2861c1c0a..292669c592afe 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -53,6 +53,9 @@ impl<'a> base::Resolver for Resolver<'a> { } fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) { + if &def.ident.name.as_str() == "macro_rules" { + self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`"); + } if def.use_locally { let ext = macro_rules::compile(&self.session.parse_sess, &def); self.add_ext(scope, def.ident, Rc::new(ext)); diff --git a/src/test/compile-fail/user-defined-macro-rules.rs b/src/test/compile-fail/user-defined-macro-rules.rs new file mode 100644 index 0000000000000..d55cef434f8d3 --- /dev/null +++ b/src/test/compile-fail/user-defined-macro-rules.rs @@ -0,0 +1,11 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +macro_rules! macro_rules { () => {} } //~ ERROR user-defined macros may not be named `macro_rules`