-
Notifications
You must be signed in to change notification settings - Fork 926
"if expression" in implicit return position (?) considered a statement #4351
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
Comments
My reading of this is that it's in alignment with the section Rust Style Guide that governs whether single lining of an if/else is possible, though I do think it would be beneficial to add some additional examples to that section in the Guide to make that explicitly clear. |
I see the if x {
0
} else {
1
} in there anywhere I can read about the rationale? However, perhaps "non- Perhaps even "non-implicit- if x {
();
} else {
()
}
// and
if x {
} else {
()
}
// but
if x { () } else { () }; |
Ahh I think I remember this one. Try adding |
What happens is that those get parsed as expression statements. It was discovered after the rustfmt 1.0 release that expression statements in the last position of their respective blocks could be formatted as expressions though, and this could use the same-line logic as well. However, because that's a breaking change it had to be version gated (this is why you have to set As far as the part of your snippet with the same in a match arm body:
This is also governed by the style rules for matches, and because from an AST perspective it's a control flow expression within the Stmt's Expr, it has to go in the block formatting (my emphasis added to pertinent section)
So your expected output shared in the OP would contradict with the style guide
Though there may be a case to be made for supporting similar single-line within the block of the arm body |
@calebcartwright is this expected behavior or should we extend the single line control flow rules to include match arms? |
Input
Output
Expected output
Meta
The "block" case is also what happens in functions, for example:
This kills the crab.
The expansion damage is also compounded by defaults of
match_arm_blocks: true
andoverflow_delimited_expr: false
.The text was updated successfully, but these errors were encountered: