File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
compiler/rustc_expand/src/mbe
tests/ui/macros/rfc-3086-metavar-expr Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,17 @@ fn parse_count<'sess>(
9393 span : Span ,
9494) -> PResult < ' sess , MetaVarExpr > {
9595 let ident = parse_ident ( iter, sess, span) ?;
96- let depth = if try_eat_comma ( iter) { Some ( parse_depth ( iter, sess, span) ?) } else { None } ;
96+ let depth = if try_eat_comma ( iter) {
97+ if iter. look_ahead ( 0 ) . is_none ( ) {
98+ return Err ( sess. span_diagnostic . struct_span_err (
99+ span,
100+ "`count` followed by a comma must have an associated index indicating its depth" ,
101+ ) ) ;
102+ }
103+ Some ( parse_depth ( iter, sess, span) ?)
104+ } else {
105+ None
106+ } ;
97107 Ok ( MetaVarExpr :: Count ( ident, depth) )
98108}
99109
Original file line number Diff line number Diff line change 1+ #![ feature( macro_metavar_expr) ]
2+
3+ macro_rules! foo {
4+ ( $( $( $t: ident) ,* ) ;* ) => { ${ count( t, ) } }
5+ //~^ ERROR `count` followed by a comma must have an associated
6+ //~| ERROR expected expression, found `$`
7+ }
8+
9+ fn test ( ) {
10+ foo ! ( a, a; b, b) ;
11+ }
12+
13+ fn main ( ) {
14+ }
Original file line number Diff line number Diff line change 1+ error: `count` followed by a comma must have an associated index indicating its depth
2+ --> $DIR/issue-111904.rs:4:37
3+ |
4+ LL | ( $( $($t:ident),* );* ) => { ${count(t,)} }
5+ | ^^^^^
6+
7+ error: expected expression, found `$`
8+ --> $DIR/issue-111904.rs:4:35
9+ |
10+ LL | ( $( $($t:ident),* );* ) => { ${count(t,)} }
11+ | ^ expected expression
12+ ...
13+ LL | foo!(a, a; b, b);
14+ | ---------------- in this macro invocation
15+ |
16+ = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
17+
18+ error: aborting due to 2 previous errors
19+
You can’t perform that action at this time.
0 commit comments