From 4c9dd747bf3e6f3b3502d75755fc083f466ed3d8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Apr 2016 20:24:30 +0100 Subject: [PATCH] Fix long generic indent --- src/items.rs | 5 +- tests/source/fn-custom-6.rs | 2 +- tests/source/fn-custom-7.rs | 2 +- tests/source/fn-custom-8.rs | 50 +++++++++++++++++++ tests/source/fn_args_layout-block.rs | 12 +++-- tests/target/fn-custom-6.rs | 2 +- tests/target/fn-custom-7.rs | 2 +- tests/target/fn-custom-8.rs | 74 ++++++++++++++++++++++++++++ tests/target/fn_args_layout-block.rs | 22 +++++++-- 9 files changed, 158 insertions(+), 13 deletions(-) create mode 100644 tests/source/fn-custom-8.rs create mode 100644 tests/target/fn-custom-8.rs diff --git a/src/items.rs b/src/items.rs index f3ba3872a91..04bb2ec4a4c 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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, diff --git a/tests/source/fn-custom-6.rs b/tests/source/fn-custom-6.rs index 7941d3a215e..1f2d740a075 100644 --- a/tests/source/fn-custom-6.rs +++ b/tests/source/fn-custom-6.rs @@ -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. diff --git a/tests/source/fn-custom-7.rs b/tests/source/fn-custom-7.rs index 98f457207e3..27c97867d26 100644 --- a/tests/source/fn-custom-7.rs +++ b/tests/source/fn-custom-7.rs @@ -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 index 00000000000..a1aebf1f38c --- /dev/null +++ b/tests/source/fn-custom-8.rs @@ -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 {} +} diff --git a/tests/source/fn_args_layout-block.rs b/tests/source/fn_args_layout-block.rs index 983ccc60d2b..b87158a4d7f 100644 --- a/tests/source/fn_args_layout-block.rs +++ b/tests/source/fn_args_layout-block.rs @@ -62,12 +62,16 @@ fn foo(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(a: Aaaaaaaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd) { + foo(); +} + +fn foo() -> (Looooooooooooooooooooooooooong, Reeeeeeeeeeeeeeeeeeeeeeeeeeeeeturn, iiiiiiiiiiiiiis, Loooooooooooooooooooooong) { + foo(); +} diff --git a/tests/target/fn-custom-6.rs b/tests/target/fn-custom-6.rs index 8c1f89173d7..74e6765847e 100644 --- a/tests/target/fn-custom-6.rs +++ b/tests/target/fn-custom-6.rs @@ -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. diff --git a/tests/target/fn-custom-7.rs b/tests/target/fn-custom-7.rs index c58678d45d9..82260d8c863 100644 --- a/tests/target/fn-custom-7.rs +++ b/tests/target/fn-custom-7.rs @@ -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 index 00000000000..bd4a379969b --- /dev/null +++ b/tests/target/fn-custom-8.rs @@ -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 { + } +} diff --git a/tests/target/fn_args_layout-block.rs b/tests/target/fn_args_layout-block.rs index b2d30018abd..cf380c649c8 100644 --- a/tests/target/fn_args_layout-block.rs +++ b/tests/target/fn_args_layout-block.rs @@ -98,10 +98,6 @@ fn foo(a: Aaaaaaaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbbb, c: Cccccccccccccccccc, d: Dddddddddddddddd) { - foo(); -} - trait Test { fn foo(a: u8) {} @@ -114,3 +110,21 @@ fn bar( ) -> String { } } + +fn foo( + a: Aaaaaaaaaaaaaaaaaaaa, + b: Bbbbbbbbbbbbbbbbb, + c: Cccccccccccccccccc, + d: Dddddddddddddddd +) { + foo(); +} + +fn foo() + -> (Looooooooooooooooooooooooooong, + Reeeeeeeeeeeeeeeeeeeeeeeeeeeeeturn, + iiiiiiiiiiiiiis, + Loooooooooooooooooooooong) +{ + foo(); +} -- 2.44.0