Skip to content

Commit 3a70df1

Browse files
committed
auto merge of #9753 : alexcrichton/rust/macro-attrs, r=brson
It's unclear to me why these currently aren't allowed, and my best guess is that a long time ago we didn't strip the ast of cfg nodes before syntax expansion. Now that this is done, I'm not certain that we should continue to prohibit this functionality. This is a step in the right direction towards #5605, because now we can add an empty `std::macros` module to the documentation with a bunch of empty macros explaining how they're supposed to be used.
2 parents 6c2cdb3 + 252d17a commit 3a70df1

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

src/libsyntax/parse/parser.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4561,9 +4561,6 @@ impl Parser {
45614561
|| self.look_ahead(2, |t| *t == token::LPAREN)
45624562
|| self.look_ahead(2, |t| *t == token::LBRACE)) {
45634563
// MACRO INVOCATION ITEM
4564-
if attrs.len() > 0 {
4565-
self.fatal("attrs on macros are not yet supported");
4566-
}
45674564

45684565
// item macro.
45694566
let pth = self.parse_path(NoTypesAllowed).path;
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2013 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+
// xfail-fast windows doesn't like compile-flags
12+
// compile-flags: --cfg foo
13+
14+
#[feature(macro_rules)];
15+
16+
#[cfg(foo)]
17+
macro_rules! foo( () => (1) )
18+
19+
#[cfg(not(foo))]
20+
macro_rules! foo( () => (2) )
21+
22+
fn main() {
23+
assert_eq!(foo!(), 1);
24+
}

src/test/compile-fail/ext-after-attrib.rs src/test/run-pass/macro-with-attrs2.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,10 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:attrs on macros are not yet supported
11+
#[feature(macro_rules)];
12+
13+
#[cfg(foo)]
14+
macro_rules! foo( () => (1) )
15+
16+
#[cfg(not(foo))]
17+
macro_rules! foo( () => (2) )
18+
19+
pub fn main() {
20+
assert_eq!(foo!(), 2);
21+
}
1222

13-
// Don't know how to deal with a syntax extension appearing after an
14-
// item attribute. Probably could use a better error message.
15-
#[foo = "bar"]
16-
fmt!("baz")
17-
fn main() { }

0 commit comments

Comments
 (0)