Skip to content

Commit b661e98

Browse files
committed
1 parent 1555074 commit b661e98

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,10 @@ fn transcribe_metavar_expr<'a>(
696696
MetaVarExprConcatElem::Var(ident) => {
697697
match matched_from_ident(dcx, *ident, interp)? {
698698
NamedMatch::MatchedSeq(named_matches) => {
699-
let curr_idx = repeats.last().unwrap().0;
700-
match &named_matches[curr_idx] {
699+
let Some((curr_idx, _)) = repeats.last() else {
700+
return Err(dcx.struct_span_err(sp.entire(), "invalid syntax"));
701+
};
702+
match &named_matches[*curr_idx] {
701703
// FIXME(c410-f3r) Nested repetitions are unimplemented
702704
MatchedSeq(_) => unimplemented!(),
703705
MatchedSingle(pnr) => {

tests/crashes/128346.rs

-13
This file was deleted.

tests/ui/macros/macro-metavar-expr-concat/repetitions.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ run-pass
2-
31
#![feature(macro_metavar_expr_concat)]
42

53
macro_rules! one_rep {
@@ -10,9 +8,29 @@ macro_rules! one_rep {
108
};
119
}
1210

11+
macro_rules! issue_128346 {
12+
( $($a:ident)* ) => {
13+
A(
14+
const ${concat($a, Z)}: i32 = 3;
15+
//~^ ERROR invalid syntax
16+
)*
17+
};
18+
}
19+
20+
macro_rules! issue_131393 {
21+
($t:ident $($en:ident)?) => {
22+
read::<${concat($t, $en)}>()
23+
//~^ ERROR invalid syntax
24+
//~| ERROR invalid syntax
25+
}
26+
}
27+
1328
fn main() {
1429
one_rep!(A B C);
1530
assert_eq!(AZ, 3);
1631
assert_eq!(BZ, 3);
1732
assert_eq!(CZ, 3);
33+
issue_128346!(A B C);
34+
issue_131393!(u8);
35+
issue_131393!(u16 le);
1836
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: invalid syntax
2+
--> $DIR/repetitions.rs:14:20
3+
|
4+
LL | const ${concat($a, Z)}: i32 = 3;
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: invalid syntax
8+
--> $DIR/repetitions.rs:22:17
9+
|
10+
LL | read::<${concat($t, $en)}>()
11+
| ^^^^^^^^^^^^^^^^^
12+
13+
error: invalid syntax
14+
--> $DIR/repetitions.rs:22:17
15+
|
16+
LL | read::<${concat($t, $en)}>()
17+
| ^^^^^^^^^^^^^^^^^
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
21+
error: aborting due to 3 previous errors
22+

0 commit comments

Comments
 (0)