Skip to content

Commit 8886818

Browse files
authored
Rollup merge of rust-lang#34495 - jseyfried:only_ident_macro_invocations, 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
2 parents 2a0c2c3 + b4611b1 commit 8886818

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
202202
&fld.cx.ecfg.features.unwrap());
203203
}
204204

205-
if path.segments.len() > 1 {
205+
if path.segments.len() > 1 || path.global || !path.segments[0].parameters.is_empty() {
206206
fld.cx.span_err(path.span, "expected macro name without module separators");
207207
return None;
208208
}

src/test/compile-fail/macro-with-seps-err-msg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:expected macro name without module separators
12-
1311
fn main() {
14-
globnar::brotz!();
12+
globnar::brotz!(); //~ ERROR expected macro name without module separators
13+
::foo!(); //~ ERROR expected macro name without module separators
14+
foo::<T>!(); //~ ERROR expected macro name without module separators
1515
}

0 commit comments

Comments
 (0)