Skip to content
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

Combine more expressions #1621

Merged
merged 12 commits into from
Jun 6, 2017
Merged

Combine more expressions #1621

merged 12 commits into from
Jun 6, 2017

Conversation

topecongiro
Copy link
Contributor

This PR allows more expressions to be combined with function calls, but not with match arms because I am not sure how combining interacts with wrap_match_arms option.

If it is prefered to wait before implementing, I am happy to close this without merging.

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, and I think the implementation will make discussion on rust-lang/style-team#61 easier. But given that we're still deciding there, could you put the control flow exprs behind an option please?

@topecongiro
Copy link
Contributor Author

Thank you for your comment!
I have no problem putting the control flow expressions behind an option.

I have a question, after #1520 (#525) rustfmt allows match expression to overflow like closure by default.
Should we disallow this exception in favour of discussion in rust-lang/style-team#61, or keep the current behaviour?

@nrc
Copy link
Member

nrc commented Jun 2, 2017

Should we disallow this exception in favour of discussion in rust-lang/style-team#61, or keep the current behaviour?

I would keep the current behaviour for now

@topecongiro
Copy link
Contributor Author

Added an option for combining control expressions and refactoring/bug fixes to avoid regressions.

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you want to merge now or improve the join issue first - either way is fine by me.

@topecongiro
Copy link
Contributor Author

Thank you for you feedback!
I would like to improve it, probabaly we should disallow combining method chain if it goes multi line.

@topecongiro
Copy link
Contributor Author

topecongiro commented Jun 4, 2017

Added commits to disallow combining method chain if it uses vertical layout and rebased to resolve conficts.

src/types.rs Outdated
Shape::legacy(budget, shape.indent + used_width))
})
.collect::<Option<Vec<_>>>()
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unfortunate, especially as the very similar example below looks better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out, this was caused by rustfmt not allowing the chain item to stay on the same line with the closing parens when context.use_block_indent() returns false.
In the similar example, .join(", ") was kept on the same line because the chain was inside the function call which was formatted in block style and hence context.use_block_indent() returned true.

@nrc
Copy link
Member

nrc commented Jun 4, 2017

I think we should perhaps default combine_control_expr to false (and add it as true to rfc-rustfmt.toml)

@topecongiro
Copy link
Contributor Author

I added commits to reflect the feedbacks.

@nrc nrc merged commit 130aa70 into rust-lang:master Jun 6, 2017
@nrc
Copy link
Member

nrc commented Jun 6, 2017

Thanks for all the changes!

@topecongiro topecongiro deleted the combining branch May 23, 2018 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants