]> git.lizzy.rs Git - rust.git/commitdiff
Break function headers earlier
authorMarcus Klaas <mail@marcusklaas.nl>
Tue, 1 Dec 2015 21:09:37 +0000 (22:09 +0100)
committerMarcus Klaas <mail@marcusklaas.nl>
Tue, 1 Dec 2015 21:09:37 +0000 (22:09 +0100)
Closes rustfmt#295.

src/items.rs
tests/source/fn-simple.rs
tests/target/fn-simple.rs

index 0f5fa1b655f36fc54cb425ac080c09ce41660bcb..e655d99cf20b701ee07f919c575e48735d64d646 100644 (file)
@@ -221,25 +221,23 @@ pub fn rewrite_required_fn(&mut self,
                                sig: &ast::MethodSig,
                                span: Span)
                                -> Option<String> {
-        // Drop semicolon or it will be interpreted as comment
+        // Drop semicolon or it will be interpreted as comment.
         let span = mk_sp(span.lo, span.hi - BytePos(1));
         let context = self.get_context();
 
-        // FIXME: silly formatting of the `.0`.
-        let mut result = try_opt!(rewrite_fn_base(&context,
-                                                  indent,
-                                                  ident,
-                                                  &sig.decl,
-                                                  Some(&sig.explicit_self),
-                                                  &sig.generics,
-                                                  sig.unsafety,
-                                                  sig.constness,
-                                                  sig.abi,
-                                                  ast::Visibility::Inherited,
-                                                  span,
-                                                  false,
-                                                  false))
-                             .0;
+        let (mut result, _) = try_opt!(rewrite_fn_base(&context,
+                                                       indent,
+                                                       ident,
+                                                       &sig.decl,
+                                                       Some(&sig.explicit_self),
+                                                       &sig.generics,
+                                                       sig.unsafety,
+                                                       sig.constness,
+                                                       sig.abi,
+                                                       ast::Visibility::Inherited,
+                                                       span,
+                                                       false,
+                                                       false));
 
         // Re-attach semicolon
         result.push(';');
@@ -1050,7 +1048,7 @@ fn rewrite_fn_base(context: &RewriteContext,
            arg_indent);
 
     // Check if vertical layout was forced by compute_budget_for_args.
-    if one_line_budget <= 0 {
+    if one_line_budget == 0 {
         if context.config.fn_args_paren_newline {
             result.push('\n');
             result.push_str(&arg_indent.to_string(context.config));
@@ -1305,28 +1303,21 @@ fn compute_budgets_for_args(context: &RewriteContext,
                             ret_str_len: usize,
                             newline_brace: bool)
                             -> (usize, usize, Indent) {
-    // Try keeping everything on the same line
+    // Try keeping everything on the same line.
     if !result.contains("\n") {
-        // 3 = `() `, space is before ret_string
+        // 3 = `() `, space is before ret_string.
         let mut used_space = indent.width() + result.len() + ret_str_len + 3;
         if !newline_brace {
             used_space += 2;
         }
-        let one_line_budget = if used_space > context.config.max_width {
-            0
-        } else {
-            context.config.max_width - used_space
-        };
+        let one_line_budget = context.config.max_width.checked_sub(used_space).unwrap_or(0);
+
+        if one_line_budget > 0 {
+            let multi_line_budget = context.config.max_width -
+                                    (indent.width() + result.len() + "()".len());
 
-        // 2 = `()`
-        let used_space = indent.width() + result.len() + 2;
-        let max_space = context.config.max_width;
-        debug!("compute_budgets_for_args: used_space: {}, max_space: {}",
-               used_space,
-               max_space);
-        if used_space < max_space {
             return (one_line_budget,
-                    max_space - used_space,
+                    multi_line_budget,
                     indent + result.len() + 1);
         }
     }
index 93c4322441706ab83c13a187d9604554add1cdef..044d494bd37df620718f22e20520e97c4cbd28f4 100644 (file)
@@ -41,3 +41,5 @@ unsafe fn generic_call(cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal,
                                               -> u8) {
     let f:  fn  ( _ , _  ) ->  _   =  panic!()  ;
 }
+
+pub fn start_export_thread<C: CryptoSchemee + 'static>(database: &Database, crypto_scheme: &C, block_size: usize, source_path: &Path) -> BonzoResult<mpsc::Consumer<'static, FileInstruction>> {}
index e5de6b0f00d1f582cdc8714caf4158caf179aab0..17a3ac0fe152dd52751bef0de023ca24ddb41e0d 100644 (file)
@@ -64,3 +64,11 @@ unsafe fn generic_call(cx: *mut JSContext,
                                                   -> u8) {
     let f: fn(_, _) -> _ = panic!();
 }
+
+pub fn start_export_thread<C: CryptoSchemee + 'static>
+    (database: &Database,
+     crypto_scheme: &C,
+     block_size: usize,
+     source_path: &Path)
+     -> BonzoResult<mpsc::Consumer<'static, FileInstruction>> {
+}