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>(
512
512
span : Span ,
513
513
ty : & str ,
514
514
) -> 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)
516
527
}
517
528
518
529
fn 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 {
5
5
(
6
6
${ count( foo, 0 ) } ,
7
7
${ 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
9
9
)
10
10
} ;
11
11
}
@@ -17,7 +17,7 @@ macro_rules! b {
17
17
${ ignore( foo) }
18
18
${ index( 0 ) } ,
19
19
${ 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
21
21
) * ) * ) *
22
22
)
23
23
} ;
@@ -30,15 +30,14 @@ macro_rules! c {
30
30
${ ignore( foo) }
31
31
${ length( 0 ) }
32
32
${ 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
34
34
) * ) *
35
35
)
36
36
} ;
37
37
}
38
38
39
-
40
39
fn main ( ) {
41
40
a ! ( { [ ( a) ] [ ( b c) ] } ) ;
42
41
b ! ( { [ a b ] } ) ;
43
- c ! ( { a } ) ;
42
+ c ! ( { a } ) ;
44
43
}
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
2
2
--> $DIR/out-of-bounds-arguments.rs:7:14
3
3
|
4
4
LL | ${count(foo, 10)},
5
5
| ^^^^^^^^^^^^^^^^
6
6
7
- error: index depth must be less than 3
7
+ error: depth parameter on meta-variable expression `index` must be less than 3
8
8
--> $DIR/out-of-bounds-arguments.rs:19:18
9
9
|
10
10
LL | ${index(10)},
11
11
| ^^^^^^^^^^^
12
12
13
- error: length depth must be less than 2
13
+ error: depth parameter on meta-variable expression `length` must be less than 2
14
14
--> $DIR/out-of-bounds-arguments.rs:32:18
15
15
|
16
16
LL | ${length(10)}
You can’t perform that action at this time.
0 commit comments