Skip to content

Commit 822dd41

Browse files
committed
Put lhs and rhs of binop on the same line if lhs is short
1 parent 0e660e4 commit 822dd41

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/expr.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ where
352352
.and_then(|s| s.sub_width(pp.suffix.len()))
353353
.and_then(|rhs_shape| rhs.rewrite(context, rhs_shape));
354354
if let Some(ref rhs_result) = rhs_orig_result {
355-
// If the rhs looks like block expression, we allow it to stay on the same line
356-
// with the lhs even if it is multi-lined.
357-
let allow_same_line = rhs_result
358-
.lines()
359-
.next()
360-
.map(|first_line| first_line.ends_with('{'))
361-
.unwrap_or(false);
355+
// If the length of the lhs is equal to or shorter than the tab width or
356+
// the rhs looks like block expression, we put the rhs on the same
357+
// line with the lhs even if the rhs is multi-lined.
358+
let allow_same_line = lhs_result.len() <= context.config.tab_spaces()
359+
|| rhs_result
360+
.lines()
361+
.next()
362+
.map(|first_line| first_line.ends_with('{'))
363+
.unwrap_or(false);
362364
if !rhs_result.contains('\n') || allow_same_line {
363365
let one_line_width = last_line_width(&lhs_result) + pp.infix.len()
364366
+ first_line_width(rhs_result) + pp.suffix.len();

0 commit comments

Comments
 (0)