]> git.lizzy.rs Git - rust.git/commitdiff
Refactor the corner case of handling long function
authorSeiichi Uchida <seuchida@gmail.com>
Tue, 11 Sep 2018 04:31:37 +0000 (13:31 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Tue, 11 Sep 2018 04:31:37 +0000 (13:31 +0900)
src/items.rs

index 7f8980dd15068fc6d1a6f8aae7be54a406314539..44d8889d832bcd707cb400108d3174cd15729181 100644 (file)
@@ -2040,18 +2040,16 @@ fn rewrite_fn_base(
         let used_width = last_line_used_width(&result, indent.width()) + first_line_width(&ret_str);
         // Put the closing brace on the next line if it overflows the max width.
         // 1 = `)`
-        if fd.inputs.is_empty() && used_width + 1 > context.config.max_width() {
-            result.push('\n');
-        }
+        let closing_paren_overflow_max_width =
+            fd.inputs.is_empty() && used_width + 1 > context.config.max_width();
         // If the last line of args contains comment, we cannot put the closing paren
         // on the same line.
-        if arg_str
+        args_last_line_contains_comment = arg_str
             .lines()
             .last()
-            .map_or(false, |last_line| last_line.contains("//"))
-        {
-            args_last_line_contains_comment = true;
-            result.push_str(&arg_indent.to_string_with_newline(context.config));
+            .map_or(false, |last_line| last_line.contains("//"));
+        if closing_paren_overflow_max_width || args_last_line_contains_comment {
+            result.push_str(&indent.to_string_with_newline(context.config));
         }
         result.push(')');
     }