Skip to content

Commit 0c7e16e

Browse files
committed
macros: Add test cases for macro repetition separators
1 parent 4fde21b commit 0c7e16e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

gcc/testsuite/rust/compile/macro9.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
macro_rules! add {
2+
($e:expr, $($es:expr),*) => {
3+
$e + add!($($es),*)
4+
};
5+
($e:expr) => {
6+
$e
7+
};
8+
}
9+
10+
fn main() -> i32 {
11+
let a = add!(15 2 9); // { dg-error "Failed to match any rule within macro" }
12+
let b = add!(15);
13+
let b = add!(15 14); // { dg-error "Failed to match any rule within macro" }
14+
let b = add!(15, 14,); // { dg-error "Failed to match any rule within macro" }
15+
16+
0
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
macro_rules! add {
2+
($e:expr, $($es:expr),*) => {
3+
$e + add!($($es),*)
4+
};
5+
($e:expr) => {
6+
$e
7+
};
8+
}
9+
10+
fn main() -> i32 {
11+
let a = add!(15, 2, 9); // 26
12+
13+
a - 26
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
macro_rules! add {
2+
($e:expr big_tok $($es:expr) big_tok *) => {
3+
$e + add!($($es) big_tok *)
4+
};
5+
($e:expr) => {
6+
$e
7+
};
8+
}
9+
10+
fn main() -> i32 {
11+
let a = add!(15 big_tok 2 big_tok 9); // 26
12+
13+
a - 26
14+
}

0 commit comments

Comments
 (0)