File tree 3 files changed +70
-0
lines changed
compiler/rustc_expand/src/mbe
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,13 @@ fn expand_macro<'cx>(
236
236
target_sp. open = source_sp. open . with_ctxt ( ctxt) ;
237
237
target_sp. close = source_sp. close . with_ctxt ( ctxt) ;
238
238
}
239
+ (
240
+ TokenTree :: Delimited ( target_sp, ..) ,
241
+ mbe:: TokenTree :: MetaVar ( source_sp, ..) ,
242
+ ) => {
243
+ target_sp. open = source_sp. with_ctxt ( ctxt) ;
244
+ target_sp. close = source_sp. with_ctxt ( ctxt) . shrink_to_hi ( ) ;
245
+ }
239
246
_ => {
240
247
let sp = rhs_tt. span ( ) . with_ctxt ( ctxt) ;
241
248
tt. set_span ( sp) ;
Original file line number Diff line number Diff line change
1
+ // compile-flags: --crate-type lib -O -C debug-assertions=yes
2
+
3
+ // Regression test for issue 118786
4
+
5
+ macro_rules! make_macro {
6
+ ( $macro_name: tt) => {
7
+ macro_rules! $macro_name {
8
+ //~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
9
+ //~| ERROR macro expansion ignores token `{` and any following
10
+ //~| ERROR cannot find macro `macro_rules` in this scope
11
+ ( ) => { }
12
+ }
13
+ }
14
+ }
15
+
16
+ make_macro ! ( ( meow) ) ;
Original file line number Diff line number Diff line change
1
+ error: macros that expand to items must be delimited with braces or followed by a semicolon
2
+ --> $DIR/issue-118786.rs:7:22
3
+ |
4
+ LL | macro_rules! $macro_name {
5
+ | ^^^^^^^^^^^
6
+ |
7
+ help: change the delimiters to curly braces
8
+ |
9
+ LL | macro_rules! {} {
10
+ | ~ +
11
+ help: add a semicolon
12
+ |
13
+ LL | macro_rules! $macro_name; {
14
+ | +
15
+
16
+ error: macro expansion ignores token `{` and any following
17
+ --> $DIR/issue-118786.rs:7:34
18
+ |
19
+ LL | macro_rules! $macro_name {
20
+ | ^
21
+ ...
22
+ LL | make_macro!((meow));
23
+ | ------------------- caused by the macro expansion here
24
+ |
25
+ = note: the usage of `make_macro!` is likely invalid in item context
26
+
27
+ error: cannot find macro `macro_rules` in this scope
28
+ --> $DIR/issue-118786.rs:7:9
29
+ |
30
+ LL | macro_rules! $macro_name {
31
+ | ^^^^^^^^^^^
32
+ ...
33
+ LL | make_macro!((meow));
34
+ | ------------------- in this macro invocation
35
+ |
36
+ note: maybe you have forgotten to define a name for this `macro_rules!`
37
+ --> $DIR/issue-118786.rs:7:9
38
+ |
39
+ LL | macro_rules! $macro_name {
40
+ | ^^^^^^^^^^^
41
+ ...
42
+ LL | make_macro!((meow));
43
+ | ------------------- in this macro invocation
44
+ = note: this error originates in the macro `make_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
45
+
46
+ error: aborting due to 3 previous errors
47
+
You can’t perform that action at this time.
0 commit comments