-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Trailing typecast syntax error when used in functions #46466
Comments
Not so much when used as functions, but when a block expression or control flow expression is used as the left expression of a binary expression that is the outer expression of an expression statement or block expression. The Reference says An expression that consists of only a block expression or control flow expression, that doesn't end a block and evaluates to |
@Havvy Thanks! If this is indeed a bug, might I perhaps grab the opportunity and get a bit more familiar with the parsing internals by fixing it myself? |
IIRC this is a known issue. The problem is basically that when the compiler see the |
Likewise, if the reference is wrong here, it might be useful to have a diagnostic for when a binary operator starts an expression statement after the implied semicolon from the control flow/block expression. |
I can see a bit of a problem with the specification in the reference: It makes parsing depend on types. Correct me if I'm wrong, but isn't type inferrence a later pass? |
Minimal reproducer: fn f() -> i8 {
{ 0 } as i8
} I was bitten by this issue when I tried to cast an |
We've changed the documentation in the reference for now. (Via rust-lang/reference#183) |
The compiler now suggests wrapping the expression with parentheses. We're tracking the grammar discussion in #54482. |
This sort of construct causes a syntax error:
Playground link
The same syntax works fine in an assignment form:
And so it is surprising that it doesn't work in a function context.
When parentheses are added, it parses in the function context too:
Playground link
The same applies to using
match
and presumably possibly other expressions as well.Seems like a bug?
The text was updated successfully, but these errors were encountered: