This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +39
-9
lines changed
compiler/rustc_expand/src/mbe Expand file tree Collapse file tree 5 files changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -512,7 +512,18 @@ fn out_of_bounds_err<'a>(
512512 span : Span ,
513513 ty : & str ,
514514) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
515- cx. struct_span_err ( span, & format ! ( "{ty} depth must be less than {max}" ) )
515+ let msg = if max == 0 {
516+ format ! (
517+ "meta-variable expression `{ty}` with depth parameter \
518+ must be called inside of a macro repetition"
519+ )
520+ } else {
521+ format ! (
522+ "depth parameter on meta-variable expression `{ty}` \
523+ must be less than {max}"
524+ )
525+ } ;
526+ cx. struct_span_err ( span, & msg)
516527}
517528
518529fn transcribe_metavar_expr < ' a > (
Original file line number Diff line number Diff line change 1+ #![ feature( macro_metavar_expr) ]
2+
3+ macro_rules! metavar {
4+ ( $i: expr ) => {
5+ ${ length( 0 ) }
6+ //~^ ERROR meta-variable expression `length` with depth parameter must be called inside of a macro repetition
7+ } ;
8+ }
9+
10+ const _: i32 = metavar ! ( 0 ) ;
11+
12+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: meta-variable expression `length` with depth parameter must be called inside of a macro repetition
2+ --> $DIR/meta-variable-depth-outside-repeat.rs:5:10
3+ |
4+ LL | ${length(0)}
5+ | ^^^^^^^^^^^
6+
7+ error: aborting due to previous error
8+
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ macro_rules! a {
55 (
66 ${ count( foo, 0 ) } ,
77 ${ count( foo, 10 ) } ,
8- //~^ ERROR count depth must be less than 4
8+ //~^ ERROR depth parameter on meta-variable expression `count` must be less than 4
99 )
1010 } ;
1111}
@@ -17,7 +17,7 @@ macro_rules! b {
1717 ${ ignore( foo) }
1818 ${ index( 0 ) } ,
1919 ${ index( 10 ) } ,
20- //~^ ERROR index depth must be less than 3
20+ //~^ ERROR depth parameter on meta-variable expression `index` must be less than 3
2121 ) * ) * ) *
2222 )
2323 } ;
@@ -30,15 +30,14 @@ macro_rules! c {
3030 ${ ignore( foo) }
3131 ${ length( 0 ) }
3232 ${ length( 10 ) }
33- //~^ ERROR length depth must be less than 2
33+ //~^ ERROR depth parameter on meta-variable expression `length` must be less than 2
3434 ) * ) *
3535 )
3636 } ;
3737}
3838
39-
4039fn main ( ) {
4140 a ! ( { [ ( a) ] [ ( b c) ] } ) ;
4241 b ! ( { [ a b ] } ) ;
43- c ! ( { a } ) ;
42+ c ! ( { a } ) ;
4443}
Original file line number Diff line number Diff line change 1- error: count depth must be less than 4
1+ error: depth parameter on meta-variable expression `count` must be less than 4
22 --> $DIR/out-of-bounds-arguments.rs:7:14
33 |
44LL | ${count(foo, 10)},
55 | ^^^^^^^^^^^^^^^^
66
7- error: index depth must be less than 3
7+ error: depth parameter on meta-variable expression `index` must be less than 3
88 --> $DIR/out-of-bounds-arguments.rs:19:18
99 |
1010LL | ${index(10)},
1111 | ^^^^^^^^^^^
1212
13- error: length depth must be less than 2
13+ error: depth parameter on meta-variable expression `length` must be less than 2
1414 --> $DIR/out-of-bounds-arguments.rs:32:18
1515 |
1616LL | ${length(10)}
You can’t perform that action at this time.
0 commit comments