File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ impl<'a> Registry<'a> {
101
101
///
102
102
/// This is the most general hook into `libsyntax`'s expansion behavior.
103
103
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
+ }
104
107
self . syntax_exts . push ( ( name, match extension {
105
108
NormalTT ( ext, _, allow_internal_unstable) => {
106
109
NormalTT ( ext, Some ( self . krate_span ) , allow_internal_unstable)
Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ impl<'a> base::Resolver for Resolver<'a> {
53
53
}
54
54
55
55
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
+ }
56
59
if def. use_locally {
57
60
let ext = macro_rules:: compile ( & self . session . parse_sess , & def) ;
58
61
self . add_ext ( scope, def. ident , Rc :: new ( ext) ) ;
Original file line number Diff line number Diff line change
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`
You can’t perform that action at this time.
0 commit comments