Re:Rust Language Cheat Sheet
by posixplz on Monday August 05, 2019 @09:34AM
(#20614032)
You’re correct. Other folks seem to be using non-Rust mental models for semicolons.
[ Parent
| on HN ]
No they're not, see steve's explanation above.
Putting a semicolon after an expression makes it into a statement, which are unit-valued, which is why the expression's value gets suppressed. It's a subset of "statements not ending with blocks" (since an expression-statement doesn't take a statement-block even if the expression itself has one).
But my comment was in reply to:
> no semicolons after things that use {}, semicolons after everything else.
Which seems fundamentally flawed for a cheatsheet. Unless you never intend to return anything with a bracket, I guess.