Skip to content

Overflow the last rhs of a binary expression #2509

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 2 commits into from
Mar 15, 2018

Conversation

topecongiro
Copy link
Contributor

@topecongiro topecongiro commented Mar 5, 2018

EDIT: this is no longer true.


This PR allows the last rhs of a binary expression to be overflowed if it is a chain.

We do not want to overflow the rhs of a binary expression that is inside the other binary expression. For example, we do not want to do these:

-        self.inner_as_ref().contains('\n')
-            || self.pre_comment
-                .as_ref()
-                .map_or(false, |s| s.contains('\n'))
-            || self.post_comment
-                .as_ref()
-                .map_or(false, |s| s.contains('\n'))
+        self.inner_as_ref().contains('\n') || self.pre_comment
+            .as_ref()
+            .map_or(false, |s| s.contains('\n')) || self.post_comment
+            .as_ref()
+            .map_or(false, |s| s.contains('\n'))
-                if !forbid_same_line⏎
-                    && (is_block⏎
-                        || (!body_str.contains('\n') && body_str.len() <= body_shape.width)) =>⏎
+                if !forbid_same_line && (is_block⏎
+                    || (!body_str.contains('\n') && body_str.len() <= body_shape.width)) =>⏎

Closes #2493.

@nrc
Copy link
Member

nrc commented Mar 8, 2018

Whilst I agree that #2493 looks bad, I think that the changes in the forth commit here are sub-optimal since they make things harder to read, IMO, because at a glance it's easy to see the chain, but miss the binary operators. I wonder if we should only do this change if the regular formatting would 'orphan' a binop as in #2493? We do something similar for chains - keeping the second element on the same line as the first if it would be an 'orphan' on its own line.

@topecongiro
Copy link
Contributor Author

I think that the changes in the forth commit here are sub-optimal since they make things harder to read, IMO, because at a glance it's easy to see the chain, but miss the binary operators.

Actually I initially liked the change in the fourth commit, but after looking it back, they look bad.

I will update this PR so that we put the rhs of a binary expression only when the lhs is shorther than or equal to the tab width.

src/lists.rs Outdated
|| self.post_comment
.as_ref()
.map_or(false, |s| s.contains('\n'))
self.inner_as_ref().contains('\n') || self.pre_comment.is_some() || self.post_comment
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I especially dislike this change 👎

@topecongiro
Copy link
Contributor Author

I have updated this PR so that we put both the lhs and the rhs on the same line when the width of the lhs is equal to or shorter than the tab width.

@nrc nrc merged commit c416246 into rust-lang:master Mar 15, 2018
@nrc
Copy link
Member

nrc commented Mar 15, 2018

Thanks!

@topecongiro topecongiro deleted the issue-2493 branch March 15, 2018 23:02
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