-
Notifications
You must be signed in to change notification settings - Fork 904
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
Add overflow_closures and overflow_match_arms opts #1898
Conversation
Thank you for you PR! Could you please add tests for |
Oops, I thought I'd done that. Will add. |
src/expr.rs
Outdated
@@ -688,6 +688,13 @@ fn rewrite_closure_expr( | |||
if classify::expr_requires_semi_to_be_stmt(left_most_sub_expr(expr)) { | |||
rewrite = and_one_line(rewrite); | |||
} | |||
rewrite = rewrite.and_then(|rw| { | |||
if !context.config.overflow_closures() && rw.contains('\n') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Totally not a rustfmt
expert, so could totally be wrong, but won't this undo any other formatting on everything else inside the expression?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at how rewrite_closure_expr
is used:
It's called to attempt to format the closure body expression without wrapping it in a block. If it fails and returns None
, rustfmt will fall back to rewrite_closure_block
and format the expression with a block surrounding it. rewrite_closure_block
will perform any formatting that's still appropriate for the expression in that context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, ok, fair enough. That happens when drive-by reviewing, thanks for explaining :)
8ccdf28
to
48b0c35
Compare
Bikeshedding, I would prefer |
@nrc That would seem to imply always forcing a block for closures and match arms, whereas this option only forces a block when the respective constructs "overflow" a single line. |
Perhaps |
I like |
multiline_closure_forces_block = false (default): result.and_then(|maybe_value| match maybe_value { None => ..., Some(value) => ..., }) multiline_closure_forces_block = true: result.and_then(|maybe_value| { match maybe_value { None => ..., Some(value) => ..., } }) multiline_match_arm_forces_block = false (default): match lorem { None => if ipsum { println!("Hello World"); }, Some(dolor) => ..., } multiline_match_arm_forces_block = true: match lorem { None => { if ipsum { println!("Hello World"); } } Some(dolor) => ..., }
48b0c35
to
411c73c
Compare
Thanks for making the changes! |
cc #1791
overflow_closures
Allow overflow on closures
true
true
,false
true
:false
:overflow_match_arms
Allow overflow on match arms
true
true
,false
true
:false
: