diff --git a/src/config.rs b/src/config.rs index 02ee8e63789..1abdc9e80b7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ extern crate toml; use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle}; -use lists::SeparatorTactic; +use lists::{SeparatorTactic, ListTactic}; use issues::ReportTactic; #[derive(Copy, Clone, Eq, PartialEq, Debug)] @@ -26,6 +26,25 @@ pub enum BlockIndentStyle { impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual); +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Density { + // Fit as much on one line as possible. + Compressed, + // Use more lines. + Tall, +} + +impl_enum_decodable!(Density, Compressed, Tall); + +impl Density { + pub fn to_list_tactic(self) -> ListTactic { + match self { + Density::Compressed => ListTactic::Mixed, + Density::Tall => ListTactic::HorizontalVertical, + } + } +} + macro_rules! create_config { ($($i:ident: $ty:ty),+ $(,)*) => ( #[derive(RustcDecodable, Clone)] @@ -70,6 +89,7 @@ create_config! { fn_brace_style: BraceStyle, fn_return_indent: ReturnIndent, fn_args_paren_newline: bool, + fn_args_layout: Density, struct_trailing_comma: SeparatorTactic, struct_lit_trailing_comma: SeparatorTactic, struct_lit_style: StructLitStyle, @@ -94,6 +114,7 @@ impl Default for Config { fn_brace_style: BraceStyle::SameLineWhere, fn_return_indent: ReturnIndent::WithArgs, fn_args_paren_newline: true, + fn_args_layout: Density::Tall, struct_trailing_comma: SeparatorTactic::Vertical, struct_lit_trailing_comma: SeparatorTactic::Vertical, struct_lit_style: StructLitStyle::BlockIndent, diff --git a/src/items.rs b/src/items.rs index bcc851a5b35..18cf58b667b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -342,7 +342,7 @@ impl<'a> FmtVisitor<'a> { } let fmt = ListFormatting { - tactic: ListTactic::HorizontalVertical, + tactic: self.config.fn_args_layout.to_list_tactic(), separator: ",", trailing_separator: SeparatorTactic::Never, indent: arg_indent, diff --git a/tests/config/small_tabs.toml b/tests/config/small_tabs.toml index 1b4ab5cb7e9..c05f173177b 100644 --- a/tests/config/small_tabs.toml +++ b/tests/config/small_tabs.toml @@ -6,6 +6,7 @@ newline_style = "Unix" fn_brace_style = "SameLineWhere" fn_return_indent = "WithArgs" fn_args_paren_newline = true +fn_args_layout = "Tall" struct_trailing_comma = "Vertical" struct_lit_trailing_comma = "Vertical" struct_lit_style = "BlockIndent" diff --git a/tests/source/fn-custom.rs b/tests/source/fn-custom.rs new file mode 100644 index 00000000000..77ced4c5e0e --- /dev/null +++ b/tests/source/fn-custom.rs @@ -0,0 +1,13 @@ +// rustfmt-fn_args_layout: Compressed +// Test some of the ways function signatures can be customised. + +// Test compressed layout of args. +fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { + foo(); +} + +impl Foo { + fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { + foo(); + } +} diff --git a/tests/target/fn-custom.rs b/tests/target/fn-custom.rs new file mode 100644 index 00000000000..01abeaebb9e --- /dev/null +++ b/tests/target/fn-custom.rs @@ -0,0 +1,15 @@ +// rustfmt-fn_args_layout: Compressed +// Test some of the ways function signatures can be customised. + +// Test compressed layout of args. +fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, + d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { + foo(); +} + +impl Foo { + fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, + d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { + foo(); + } +}