Skip to content

Format the if expression at the end of the block in a single line #3338

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

Merged
merged 6 commits into from
Mar 11, 2019

Conversation

topecongiro
Copy link
Contributor

This PR is a successor of #2778. Huge thanks to @csmoe for tackling to this in the first place.

Closes #2777.

{
let shape = self.shape();
let rewrite = self.with_context(|ctx| {
format_expr(stmt_expr(&stmts[0])?, ExprType::SubExpression, ctx, shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in theory applicable to any expression kind rather than to if only.
Basically, the rule is "print trailing expressions as expressions, rather than statements".

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure where else that would make a difference though.

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, I think that's right. The only thing to take into account is if the last expression is one of continue, return or break, then we need to add a trailing semicolon. I'll see if I can simplify this a bit more.

@otavio
Copy link
Contributor

otavio commented Feb 13, 2019

Also, could in the end, this to be squashed on a single commit?

@topecongiro topecongiro merged commit 5f3dfe6 into rust-lang:master Mar 11, 2019
@topecongiro topecongiro deleted the single-line-if-expr branch March 11, 2019 14:18
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.

4 participants