]> git.lizzy.rs Git - rust.git/commitdiff
Fix long generic indent
authorErik Johnston <erikj@jki.re>
Thu, 7 Apr 2016 19:24:30 +0000 (20:24 +0100)
committerErik Johnston <erikj@jki.re>
Thu, 7 Apr 2016 19:29:05 +0000 (20:29 +0100)
src/items.rs
tests/source/fn-custom-6.rs
tests/source/fn-custom-7.rs
tests/source/fn-custom-8.rs [new file with mode: 0644]
tests/source/fn_args_layout-block.rs
tests/target/fn-custom-6.rs
tests/target/fn-custom-7.rs
tests/target/fn-custom-8.rs [new file with mode: 0644]
tests/target/fn_args_layout-block.rs

index f3ba3872a9178f40dd67fef759cb85aa151bd493..04bb2ec4a4c65fba575942893507507b550cd721 100644 (file)
@@ -1290,12 +1290,13 @@ fn rewrite_fn_base(context: &RewriteContext,
     };
 
     // Args.
-    let (mut one_line_budget, multi_line_budget, mut arg_indent) =
+    let (mut one_line_budget, mut multi_line_budget, mut arg_indent) =
         compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace);
 
     if context.config.fn_args_layout == FnArgLayoutStyle::Block ||
        context.config.fn_args_layout == FnArgLayoutStyle::BlockAlways {
         arg_indent = indent.block_indent(context.config);
+        multi_line_budget = context.config.max_width - arg_indent.width();
     }
 
     debug!("rewrite_fn: one_line_budget: {}, multi_line_budget: {}, arg_indent: {:?}",
@@ -1569,6 +1570,8 @@ enum ArgumentKind<'a> {
         _ => multi_line_budget,
     };
 
+    debug!("rewrite_args: budget: {}, tactic: {:?}", budget, tactic);
+
     let end_with_newline = match context.config.fn_args_layout {
         FnArgLayoutStyle::Block | FnArgLayoutStyle::BlockAlways => true,
         _ => false,
index 7941d3a215eb7abfef7dc358f37f3a8ea0b6ef4a..1f2d740a075da5eeb8211762374e663ccd423e42 100644 (file)
@@ -1,4 +1,4 @@
-// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_layout: BlockAlways
 // rustfmt-where_indent: Inherit
 // rustfmt-fn_brace_style: PreferSameLine
 // Test different indents.
index 98f457207e3616f7cd4328ab4a8ab8e6b740520f..27c97867d265274ea1125121bc9c46122e569138 100644 (file)
@@ -1,4 +1,4 @@
-// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_layout: BlockAlways
 // rustfmt-fn_args_density: Vertical
 // rustfmt-fn_arg_indent: Tabbed
 // rustfmt-fn_brace_style: AlwaysNextLine
diff --git a/tests/source/fn-custom-8.rs b/tests/source/fn-custom-8.rs
new file mode 100644 (file)
index 0000000..a1aebf1
--- /dev/null
@@ -0,0 +1,50 @@
+// rustfmt-fn_args_layout: Block
+// rustfmt-where_indent: Inherit
+// rustfmt-fn_brace_style: PreferSameLine
+// Test different indents.
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {
+    foo();
+}
+
+fn bar(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee) {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String {
+    foo();
+}
+
+fn bar(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee) -> String {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) where T: UUUUUUUUUUU {
+    foo();
+}
+
+fn bar(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee) where T: UUUUUUUUUUU {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String where T: UUUUUUUUUUU {
+    foo();
+}
+
+fn bar(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee) -> String where T: UUUUUUUUUUU {
+    bar();
+}
+
+trait Test {
+    fn foo(
+        a: u8) {
+
+    }
+
+    fn bar(a: u8)
+    -> String {
+
+    }
+
+    fn bar(a: u8) -> String where Foo: foooo, Bar: barrr {}
+}
index 983ccc60d2bd022b1f6c9e9003d5adac69c9ac5f..b87158a4d7f8b0a827ce5ed18dd07a794d175045 100644 (file)
@@ -62,12 +62,16 @@ fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Looooo
     foo();
 }
 
-fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Loooooooooooooooong>(a: Aaaaaaaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd) {
-    foo();
-}
-
 trait Test {
     fn foo(a: u8) {}
 
     fn bar(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee) -> String {}
 }
+
+fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Loooooooooooooooong>(a: Aaaaaaaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd) {
+    foo();
+}
+
+fn foo() -> (Looooooooooooooooooooooooooong, Reeeeeeeeeeeeeeeeeeeeeeeeeeeeeturn, iiiiiiiiiiiiiis, Loooooooooooooooooooooong) {
+    foo();
+}
index 8c1f89173d773947f36631b8c228f9214f29b0f4..74e6765847e8cc6edb579c4a2cabc8840b14ca89 100644 (file)
@@ -1,4 +1,4 @@
-// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_layout: BlockAlways
 // rustfmt-where_indent: Inherit
 // rustfmt-fn_brace_style: PreferSameLine
 // Test different indents.
index c58678d45d977b7c400f9c2cf3f3862b3ae71cdc..82260d8c8632c0b11d5bb021492a93eb60715d94 100644 (file)
@@ -1,4 +1,4 @@
-// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_layout: BlockAlways
 // rustfmt-fn_args_density: Vertical
 // rustfmt-fn_arg_indent: Tabbed
 // rustfmt-fn_brace_style: AlwaysNextLine
diff --git a/tests/target/fn-custom-8.rs b/tests/target/fn-custom-8.rs
new file mode 100644 (file)
index 0000000..bd4a379
--- /dev/null
@@ -0,0 +1,74 @@
+// rustfmt-fn_args_layout: Block
+// rustfmt-where_indent: Inherit
+// rustfmt-fn_brace_style: PreferSameLine
+// Test different indents.
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {
+    foo();
+}
+
+fn bar(
+    a: Aaaaaaaaaaaaaa,
+    b: Bbbbbbbbbbbbbb,
+    c: Cccccccccccccccccc,
+    d: Dddddddddddddddd,
+    e: Eeeeeeeeeeeeeee
+) {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String {
+    foo();
+}
+
+fn bar(
+    a: Aaaaaaaaaaaaaa,
+    b: Bbbbbbbbbbbbbb,
+    c: Cccccccccccccccccc,
+    d: Dddddddddddddddd,
+    e: Eeeeeeeeeeeeeee
+) -> String {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb)
+where T: UUUUUUUUUUU {
+    foo();
+}
+
+fn bar(
+    a: Aaaaaaaaaaaaaa,
+    b: Bbbbbbbbbbbbbb,
+    c: Cccccccccccccccccc,
+    d: Dddddddddddddddd,
+    e: Eeeeeeeeeeeeeee
+) where T: UUUUUUUUUUU {
+    bar();
+}
+
+fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String
+where T: UUUUUUUUUUU {
+    foo();
+}
+
+fn bar(
+    a: Aaaaaaaaaaaaaa,
+    b: Bbbbbbbbbbbbbb,
+    c: Cccccccccccccccccc,
+    d: Dddddddddddddddd,
+    e: Eeeeeeeeeeeeeee
+) -> String
+where T: UUUUUUUUUUU {
+    bar();
+}
+
+trait Test {
+    fn foo(a: u8) {}
+
+    fn bar(a: u8) -> String {}
+
+    fn bar(a: u8) -> String
+    where Foo: foooo,
+          Bar: barrr {
+    }
+}
index b2d30018abd48ae8594c4b15626cabc4a6c1ff8c..cf380c649c8d132586be9f9e7f4d4150ae2e89a0 100644 (file)
@@ -98,10 +98,6 @@ fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Looooo
     foo();
 }
 
-fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Loooooooooooooooong>(a: Aaaaaaaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd) {
-    foo();
-}
-
 trait Test {
     fn foo(a: u8) {}
 
@@ -114,3 +110,21 @@ fn bar(
     ) -> String {
     }
 }
+
+fn foo<L: Loooooooooooooooooooong, G: Geeeeeeeeeeneric, I: iiiiiiiiis, L: Loooooooooooooooong>(
+    a: Aaaaaaaaaaaaaaaaaaaa,
+    b: Bbbbbbbbbbbbbbbbb,
+    c: Cccccccccccccccccc,
+    d: Dddddddddddddddd
+) {
+    foo();
+}
+
+fn foo()
+    -> (Looooooooooooooooooooooooooong,
+        Reeeeeeeeeeeeeeeeeeeeeeeeeeeeeturn,
+        iiiiiiiiiiiiiis,
+        Loooooooooooooooooooooong)
+{
+    foo();
+}