Skip to content

Commit 7b2bfa3

Browse files
Rollup merge of #146064 - jullanggit:patch-1, r=fmease
Add compiler error when trying to use concat metavar expr in repetitions ## Disclaimer This is my first PR to rust, so if I missed/could improve something about this PR, please excuse and tell me! ## The improvement The [metavar_expr_concat feature](#124225) currently does not seem to support nested repetitions, and throws an ICE without much explanation if the relevant code path is hit. This PR adds a draft compiler error that attempts to explain the issue. I am not 100% sure what all the ways of triggering this error are, so the message is currently pretty generic, please do correct me if there's something wrong with it or it could be improved. Thank you for you time! Fixes #140479.
2 parents 5d855c6 + f6e7c81 commit 7b2bfa3

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
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
}

tests/crashes/140479.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// issue: <https://github.com/rust-lang/rust/issues/140479>
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:14:30
3+
|
4+
LL | ${concat(_, $arg)}
5+
| ^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)