-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: parse block and if statements independently of expressions in s…
…tatements (#5634) # Description ## Problem Resolves #5228 ## Summary The reason why this was parsed fine: ```rust fn foo() { for i in 0..10 { } -1 } ``` but this wasn't: ```rust fn foo() { {} -1 } ``` is that a for expression is parsed as a statement choice, but a block was just parsed as part of an expression. Because of this, if you had `{} - 1` it was parsed as an infix expression. Note that that infix expression is still valid if it's supposed to be an expression, for example: ```rust let x = { 10 } - 1; ``` However, there's a difference if that `{` appears as a stand-alone statement: in that case it shouldn't be considered an expression that can form part of other expressions. The same thing was done with `if`, which before this PR could never show up as a stand-alone statement. I checked with Rust and this is the same there (I didn't check their implementation, just that our behavior now matches that of Rust). ## Additional Context This is a breaking change. If code relied on this behavior, it will now require parentheses around it. For example, this used to work (there was one case in our codebase): ```rust if 1 { 2 } else { 3 } as Field ``` Now it must be written like this: ```rust (if 1 { 2 } else { 3 }) as Field ``` But, again, this is the same as Rust. ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
5 changed files
with
68 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters