Skip to content

Commit

Permalink
Rollup merge of rust-lang#34495 - jseyfried:only_ident_macro_invocati…
Browse files Browse the repository at this point in the history
…ons, r=eddyb

Forbid type parameters and global paths in macro invocations

Fixes rust-lang#28558.
This is a [breaking-change]. For example, the following would break:
```rust
macro_rules! m { () => { () } }
fn main() {
    m::<T>!(); // Type parameters are no longer allowed in macro invocations
    ::m!(); // Global paths are no longer allowed in macro invocations
}
```
Any breakage can be fixed by removing the type parameters or the leading `::` (respectively).

r? @eddyb
  • Loading branch information
Manishearth committed Jun 29, 2016
2 parents 2a0c2c3 + b4611b1 commit 8886818
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
&fld.cx.ecfg.features.unwrap());
}

if path.segments.len() > 1 {
if path.segments.len() > 1 || path.global || !path.segments[0].parameters.is_empty() {
fld.cx.span_err(path.span, "expected macro name without module separators");
return None;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/macro-with-seps-err-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:expected macro name without module separators

fn main() {
globnar::brotz!();
globnar::brotz!(); //~ ERROR expected macro name without module separators
::foo!(); //~ ERROR expected macro name without module separators
foo::<T>!(); //~ ERROR expected macro name without module separators
}

0 comments on commit 8886818

Please sign in to comment.