For punctuation-separated sequences, most of the time Rust does not require punctuation when {}
is used. For example:
expr; // Semicolon required
{ expr; } // No semicolon required
match expr {
() => (), // Comma required
() => {} // No comma required
_ => {}
}
struct X; // Semicolon required
struct X(i32); // Semicolon required
struct X { x: i32 } // No semicolon required
Therefore I find it somewhat inconsistent that commas are required even when using {}
in enum
declarations:
enum X {
A, // Comma required
B(i32), // Comma required
C { x: i32 }, // Comma required
D,
}
This has tripped me up many times recently, and I think it would be nice if the syntax for enums could be brought to be more inline with the rest of the language.
Obviously this has downsides:
- Churn: if the rustfmt defaults change that would render lots of current Rust code incorrectly formatted. To avoid the churn this could be released as part of 2021 edition.
- Parsing difficultly: it makes parsing enum declarations harder as not everything is separated by commas.
And I don't know whether this even bothers anyone else other than me, so I'd like to hear your experiences with that.