Skip to content

Commit 99dc5b4

Browse files
committed
Add compiler error when trying to use concat metavar expr in repetitions
Replace unimplemented()! with a more helpful compiler error.
1 parent 564ee21 commit 99dc5b4

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,12 @@ fn metavar_expr_concat<'tx>(
556556
};
557557
match &named_matches[*curr_idx] {
558558
// FIXME(c410-f3r) Nested repetitions are unimplemented
559-
MatchedSeq(_) => unimplemented!(),
559+
MatchedSeq(_) => {
560+
return Err(dcx.struct_span_err(
561+
ident.span,
562+
"nested repetitions with `${concat(...)}` metavariable expressions are not yet supported",
563+
));
564+
}
560565
MatchedSingle(pnr) => extract_symbol_from_pnr(dcx, pnr, ident.span)?,
561566
}
562567
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// PR 146064
2+
// Ensure a proper compiler error, instead of an ICE occurs.
3+
// FIXME(macro_metavar_expr_concat): this error message could be improved
4+
#![feature(macro_metavar_expr_concat)]
5+
6+
macro_rules! InRepetition {
7+
(
8+
$(
9+
$($arg:ident),+
10+
)+
11+
) => {
12+
$(
13+
$(
14+
${concat(_, $arg)} //~ ERROR nested repetitions with `${concat(...)}` metavariable expressions are not yet supported
15+
)*
16+
)*
17+
};
18+
}
19+
InRepetition!(other);
20+
21+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: nested repetitions with `${concat(...)}` metavariable expressions are not yet supported
2+
--> $DIR/in-repetition.rs:16:30
3+
|
4+
LL | ${concat(_, $arg)}
5+
| ^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)