Every time I switch back to Rust from languages that finally have done away with the mostly redundant need for semicolons and commas everywhere, I get really annoyed.
As I see the Rust syntax, in most places they are really optional and not required for correctly parsing the code.
Here are the places I think they could just be dropped, without complicating the parser much:
- extern crate xxx**;**
- use std::fs**;**
- struct X { some_struct_field: u64**,** }
- enum…
- trait T { fn f(); }
In all those examples, the parser has to detect a path or a (return) type, which should be perfectly possible without the terminator. No expressions are involved here, which would be a lot harder to detect without ambiguity / backtracking / more extensive lookahead.
Making those optional should be backwards compatible, and already would have a nice convenience impact.
The parser would optionally accept a newline instead of a semicolon in those places.
The semicolon after expressions can be annoying too (at least for me), but it actually carries semantic meaning and probably can’t be touched.
Swift is a good example here, because it is very close to Rust syntax/feature wise (traditional C family, but with generics, pattern matching, lambdas, …), and is perfectly fine without them.
What do you think?