Comment

Comment by steveklabnik

> AFAIK statements /are/ essentially expressions that yield `()`

This isn't true. The inverse is true, "expression statements" can turn an expression into a statement.

What you're seeing in the playground is just how blocks are defined[1]:

> The syntax for a block is {, then any inner attributes, then any number of statements, then an optional expression, called the final operand, and finally a }.

In this case, you have one statement, and no optional expression.

And so:

> The type of a block is the type of the final operand, or () if the final operand is omitted.

So that's how this works.

Now, that being said, I don't think it's too terrible of a mental model to think of this situation in that way. But if we're getting into nitty-gritty details, that's not actually how it works.

1. https://doc.rust-lang.org/stable/reference/expressions/block...

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton