diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-06-29 21:21:22 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-29 21:21:22 +0530 |
| commit | 8886818a9ab3e6c52651038d4e22e2d51b932bb9 (patch) | |
| tree | b7df117c5afe9c843b3492a3961e41b1b7b7a164 | |
| parent | 2a0c2c3b3a0c7291f6160f9cf4178ecbdb920f04 (diff) | |
| parent | b4611b1ff29d93ba9a03932b316935cbfd076ed9 (diff) | |
| download | rust-8886818a9ab3e6c52651038d4e22e2d51b932bb9.tar.gz rust-8886818a9ab3e6c52651038d4e22e2d51b932bb9.zip | |
Rollup merge of #34495 - jseyfried:only_ident_macro_invocations, r=eddyb
Forbid type parameters and global paths in macro invocations
Fixes #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
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-with-seps-err-msg.rs | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index aca1fae6a3c..c670283e559 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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; } diff --git a/src/test/compile-fail/macro-with-seps-err-msg.rs b/src/test/compile-fail/macro-with-seps-err-msg.rs index 95250e36b86..408bb15ba28 100644 --- a/src/test/compile-fail/macro-with-seps-err-msg.rs +++ b/src/test/compile-fail/macro-with-seps-err-msg.rs @@ -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 } |
