-
Notifications
You must be signed in to change notification settings - Fork 56
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
Delimited expressions should be allowed as last argument #149
Comments
Thanks for sharing your perspective but I think it probably makes sense to close given the age of the issue, existing contrary prescription of the style guide, and the presence of a configuration option that supports the desired style (though not by default). The config option exists precisely to support those that shared your opinion, but I don't see how we could completely reverse course on the style guide and formatting behavior that would deliberately introduce breaking formatting changes. Will leave open for a bit longer for any follow up dialog, but will likely close down the road |
Man I've taken a while to respond, sorry about that.
The 13 includes some quite popular projects, such as: Now to address your points.
Breaking formatting happens pretty often in my experience. And this kind of formatting change is the least bad in my opinion: it only reduces whitespace. I also don't think it's a reversal of course. I'd say it makes the styling more consistent, instead of having the single exception of closures. This is one of those cases that some types of projects hit way more often than others, but when you hit it, it's practically necessary to enable the option. |
This isn't a change we could make in the current rustfmt. It's potentially reasonable to consider for rustfmt in a new edition. |
Thanks for sharing those findings @pitaj and no worries on the timing. As Josh noted this isn't a change that could be readily made due to stability guarantees so we've got time to discuss and brainstorm. I don't want detour the conversation too much as I think this thread will be best served by focusing on the merits for/against making the change, but will respond to a couple of your points to reinforce why we can't simply make the change (yet) even if you get everyone on board.
Think we may be using the terminology in different ways, or perhaps there's some important nuance that's missing. Due to the formatting stability guarantee, we can't decide to have rustfmt format something differently by default (even if it's better), and that in turn limits what changes we can (currently) make to the style guide which dictates rustfmt's default. It's true that there have been cases where users would run a That's anticipated/allowed, whereas the type of change you're proposing explicitly modifies formatting behavior, and would be analogous to reformating those 987 other repositories with We do have some plans for providing a transition/evolution process to formatting (both rustfmt and the style guide) though so your proposal is certainly something that could be incorporated in the next evolution |
Thank you for your thoughtful response. I look forward to working together in the future to hopefully improve this default. |
FWIW, regarding my historical comments that were quoted in the opening post here: I no longer hold that position or have those concerns, and would be happy to see this enabled by default in a new style edition. |
… r=joshtriplett [style edition 2024] Combine all delimited exprs as last argument Closes rust-lang/style-team#149 If this is merged, the rustfmt option `overflow_delimited_expr` should be enabled by default in style edition 2024. [Rendered](https://github.com/pitaj/rust/blob/style-delimited-expressions/src/doc/style-guide/src/expressions.md#combinable-expressions) r? joshtriplett
… r=joshtriplett [style edition 2024] Combine all delimited exprs as last argument Closes rust-lang/style-team#149 If this is merged, the rustfmt option `overflow_delimited_expr` should be enabled by default in style edition 2024. [Rendered](https://github.com/pitaj/rust/blob/style-delimited-expressions/src/doc/style-guide/src/expressions.md#combinable-expressions) r? joshtriplett
Rollup merge of rust-lang#114764 - pitaj:style-delimited-expressions, r=joshtriplett [style edition 2024] Combine all delimited exprs as last argument Closes rust-lang/style-team#149 If this is merged, the rustfmt option `overflow_delimited_expr` should be enabled by default in style edition 2024. [Rendered](https://github.com/pitaj/rust/blob/style-delimited-expressions/src/doc/style-guide/src/expressions.md#combinable-expressions) r? joshtriplett
(this was originally a comment in #61)
I'm trying to dig up why the rustfmt
overflow_delimited_expr
shouldn't be enabled by default. And I found it derives from the following statement in the guideHistory
I see in this comment @joshtriplett says
In the next comment they suggest a possible exception for format macros
AFAIK this did not make it into the guide
Then @nrc suggests an exception for closures as the last argument in this comment and @joshtriplett agrees
This did make it into the guide
Then there's a lot of discussion about what control flow expressions should be allowed.
Then there's discussion about arrays where @kennytm brings up arrays and @joshtriplett agrees that it should be treated similarly.
However, there was never any discussion about allowing arrays, match, and other delimited expressions as the last argument.
Getting to the point
I don't see any reason why other multi-line delimited expressions shouldn't be allowed by default in the same context as closures. For instance, right now, rustfmt will format a match inside a closure and a match without a closure differently:
That doesn't make any sense to me, and looks super ugly. Also, consider an
append
macro, used to push a list of elements to a Vec without copying or cloning:Awesome for cleaning up dozens of lines of
v.push(...)
calls into an easily readable format. But rustfmt just kills me here (without enabling theoverflow_delimited_expr
option):So my question is, why does this "last argument exception" not apply to match, arrays,
vec![]
, etc? Seems inconsistent, yet alone ugly.The text was updated successfully, but these errors were encountered: