]> git.lizzy.rs Git - rust.git/commitdiff
Put lhs and rhs of binop on the same line if lhs is short
authorSeiichi Uchida <seuchida@gmail.com>
Thu, 8 Mar 2018 08:21:30 +0000 (17:21 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Thu, 8 Mar 2018 08:21:30 +0000 (17:21 +0900)
src/expr.rs

index 2945f03a535867174526117e0be8d57c6b3fd311..d6603659c7fa9c4b0ad2ab6cebaab53ae8a2cbd0 100644 (file)
@@ -352,13 +352,15 @@ pub fn rewrite_pair<LHS, RHS>(
         .and_then(|s| s.sub_width(pp.suffix.len()))
         .and_then(|rhs_shape| rhs.rewrite(context, rhs_shape));
     if let Some(ref rhs_result) = rhs_orig_result {
-        // If the rhs looks like block expression, we allow it to stay on the same line
-        // with the lhs even if it is multi-lined.
-        let allow_same_line = rhs_result
-            .lines()
-            .next()
-            .map(|first_line| first_line.ends_with('{'))
-            .unwrap_or(false);
+        // If the length of the lhs is equal to or shorter than the tab width or
+        // the rhs looks like block expression, we put the rhs on the same
+        // line with the lhs even if the rhs is multi-lined.
+        let allow_same_line = lhs_result.len() <= context.config.tab_spaces()
+            || rhs_result
+                .lines()
+                .next()
+                .map(|first_line| first_line.ends_with('{'))
+                .unwrap_or(false);
         if !rhs_result.contains('\n') || allow_same_line {
             let one_line_width = last_line_width(&lhs_result) + pp.infix.len()
                 + first_line_width(rhs_result) + pp.suffix.len();