Skip to content

Commit b534c4d

Browse files
authored
Address * with trailing commas
1 parent 542a85e commit b534c4d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

text/0000-macro-at-most-once-rep.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Currently, the best way to make a rule tolerate trailing commas is to create ano
4747

4848
```rust
4949
macro_rules! foo {
50-
($(pat),*,) => { foo!( $(pat),* ) };
51-
($(pat),*) => {
50+
 ($(pat),+,) => { foo!( $(pat),+ ) };
51+
 ($(pat),+) => {
5252
// do stuff
5353
}
5454
}
@@ -58,7 +58,7 @@ or to allow multiple trailing commas:
5858

5959
```rust
6060
macro_rules! foo {
61-
($(pat),* $(,)*) => {
61+
 ($(pat),+ $(,)*) => {
6262
// do stuff
6363
}
6464
}
@@ -68,7 +68,7 @@ This is unergonomic and clutters up macro definitions needlessly. Under this RFC
6868

6969
```rust
7070
macro_rules! foo {
71-
($(pat),* $(,)?) => {
71+
 ($(pat),+ $(,)?) => {
7272
// do stuff
7373
}
7474
}
@@ -132,6 +132,8 @@ Drawbacks
132132
---------
133133
While there are grammar ambiguities, they can be easily fixed.
134134

135+
Also, for patterns that use `*`, `?` is not a perfect solution: `$(pat),* $(,)?` still allows `,` which is a bit weird. However, this is still an improvement over `$(pat),* $(,)*` which allows `,,,,,`.
136+
135137
Rationale and Alternatives
136138
--------------------------
137139

0 commit comments

Comments
 (0)