[rust-dev] RFC: Ignore trailing semicolons

Patrick Walton pwalton at mozilla.com
Wed Aug 1 20:47:32 PDT 2012

On 08/01/2012 07:03 PM, Glenn Willen wrote:
> I for one liked the clear and unambiguous rule: semicolon discards
> value, no-semicolon returns value.
> The idea of allowing uniform semicolon use is appealing, but it does
> seem to add complexity and mysteriousness.

Actually, the only parser change was to throw away semicolons before the 
end of the block.

To be more concrete, the rules are:

1. The last expression is the value of the block, regardless of whether 
there's a semicolon after it. (This seems like a simplification to me.)

2. "Statement positions" are defined as the position of any expression 
immediately before a ";" (if that ";" has anything after it) and the 
last value of a function declared to return unit. Given that:

3. The type of an expression in a statement position is ignored.

4. The types of the arms of a pattern match and the bodies of if/else 
statements in statement position are ignored.

I think the rules are pretty simple, but I'm biased :)

Also, the pretty printer will never write a semicolon after an 
expression in trailing position, so if you like the visual consistency 
the pretty printer will preserve it for you.

(Somewhat surprised at the response here, actually; this thread from 8 
months ago [1] had near-unanimity the other way!)


[1]: https://mail.mozilla.org/pipermail/rust-dev/2012-January/001263.html

More information about the Rust-dev mailing list