-
Notifications
You must be signed in to change notification settings - Fork 488
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
Flaw/inconsistency between block expression description and rustc. #762
Comments
ExpressionWithoutBlock isn't intended to convey that it is the only kind of "tail expression" in a block. It's intended to convey that ExpressionWithoutBlock can only appear at the end of a block. Blocks as expressions are part of the Statement rule (ExpressionStatement -> ExpressionWithBlock). This is subtly organized to properly handle This was written with the concept that a block consists of N statements with Should also probably clarify the sentence "The type of ExpressionWithBlock expressions when used as statements must be the unit type." as this was intended to cover this case, but that is worded poorly. I guess we should decide if a block is defined as "N statements plus a tail expression" or if it is "N statements, and the value is the last statement". I think rustc uses the latter (probably easier to implement), but maybe the former is a better mental model? The former is how I think of it conceptually. |
@ehuss Thank you for confirming that the compiler's behavior is the source of truth in this case here! I don't have opinion on which is the better choice here. If the first is chosen, i think it'll be good to also unify the wording of "tail expression" and "final expression" too, since both are occurring in the text; if the second is chosen, maybe we'll need to write something about "value of statement", e.g. assign unit values to declaration statements, and use the expression values as the value of expression statements. |
This doesn't help: the grammar is actually unambiguous here, so it doesn't matter whether + is greedy. It's just that the grammar has a symbol called Also the textual description below isn't clear about this. It talks about "final optional expression" but it doesn't say that when the last thing in a block is an |
The grammar in the Reference is correct here, but could be improved for clarity. We'll close this issue in favor of: |
Currently this compiles:
According to https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html , the {3} part cannot be parsed as tail expression, since it's not
ExpressionWithoutBlock
. If it is parsed asStatement
, then there should be a compile error, because its type is not()
and the semicolon could not be not eliminated.@Centril
The text was updated successfully, but these errors were encountered: