Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that expressions in non-trailing expression statements without semicolon must have type () #625

Open
petrochenkov opened this issue Jun 20, 2019 · 2 comments
Labels
A-types Area: Types Enhancement Improvement in a non-prose section of the book

Comments

@petrochenkov
Copy link
Contributor

cc rust-lang/rust#61753

@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2019

Can you say more about what is missing? In https://doc.rust-lang.org/nightly/reference/statements.html#expression-statements it says:

The type of ExpressionWithBlock expressions when used as statements must be the unit type.

And here "ExpressionWithBlock" means an expression statement without a semicolon. It's not explicit about whether or not it is "trailing" because a block expression defines the trailing expression as "ExpressionWithoutBlock".

It seems to be essentially what you are asking for?

@petrochenkov
Copy link
Contributor Author

Nice!
Didn't found that.

That paragraph covers this issue, except that the code example is not good:

// if true {
//   1
// }

That's a type mismatch between if and (implicit) else results, not the mismatch with the () expected from non-trailing expression statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-types Area: Types Enhancement Improvement in a non-prose section of the book
Projects
None yet
Development

No branches or pull requests

3 participants