-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Errormessage regarding curly braces in for statement #42982
Comments
The same thing happens with an if statement: struct X {}
if let X {} = X {} {}
|
The parser cannot differentiate between a struct literal and a "path" (a variable) followed by a block in these places. There's no way to do so at parse time, as you don't yet know wether the found path is a struct so it could be parsed as such, so the parser just flat out doesn't allow that construct. What could be improved is
The second would be harder as at this point the compiler already decided that we meant |
…cts, r=nikomatsakis Suggest parentheses when a struct literal needs them When writing a struct literal in an expression that expects a block to be started afterwards (like an `if` statement), do not suggest using the same struct literal: ``` did you mean `S { /* fields * /}`? ``` Instead, suggest surrounding the expression with parentheses: ``` did you mean `(S { /* fields * /})`? ``` Fix rust-lang#47360, rust-lang#50090. Leaving rust-lang#42982 open to come back to this problem with a better solution.
I got the following code:
I don't know if the case without surrounding parentheses is intended to work but apart from that the error message is somewhat missleading.
It seems that the tokenizer doesn't get this right?
Edit: Include error message
The text was updated successfully, but these errors were encountered: