Skip to content

Commit 89cda8d

Browse files
committed
Option to pack fn args on fewer lines
1 parent 71d24e9 commit 89cda8d

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

src/config.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
extern crate toml;
1212

1313
use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle};
14-
use lists::SeparatorTactic;
14+
use lists::{SeparatorTactic, ListTactic};
1515
use issues::ReportTactic;
1616

1717
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
@@ -26,6 +26,25 @@ pub enum BlockIndentStyle {
2626

2727
impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual);
2828

29+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
30+
pub enum Density {
31+
// Fit as much on one line as possible.
32+
Compressed,
33+
// Use more lines.
34+
Tall,
35+
}
36+
37+
impl_enum_decodable!(Density, Compressed, Tall);
38+
39+
impl Density {
40+
pub fn to_list_tactic(self) -> ListTactic {
41+
match self {
42+
Density::Compressed => ListTactic::Mixed,
43+
Density::Tall => ListTactic::HorizontalVertical,
44+
}
45+
}
46+
}
47+
2948
macro_rules! create_config {
3049
($($i:ident: $ty:ty),+ $(,)*) => (
3150
#[derive(RustcDecodable, Clone)]
@@ -70,6 +89,7 @@ create_config! {
7089
fn_brace_style: BraceStyle,
7190
fn_return_indent: ReturnIndent,
7291
fn_args_paren_newline: bool,
92+
fn_args_layout: Density,
7393
struct_trailing_comma: SeparatorTactic,
7494
struct_lit_trailing_comma: SeparatorTactic,
7595
struct_lit_style: StructLitStyle,
@@ -94,6 +114,7 @@ impl Default for Config {
94114
fn_brace_style: BraceStyle::SameLineWhere,
95115
fn_return_indent: ReturnIndent::WithArgs,
96116
fn_args_paren_newline: true,
117+
fn_args_layout: Density::Tall,
97118
struct_trailing_comma: SeparatorTactic::Vertical,
98119
struct_lit_trailing_comma: SeparatorTactic::Vertical,
99120
struct_lit_style: StructLitStyle::BlockIndent,

src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<'a> FmtVisitor<'a> {
342342
}
343343

344344
let fmt = ListFormatting {
345-
tactic: ListTactic::HorizontalVertical,
345+
tactic: self.config.fn_args_layout.to_list_tactic(),
346346
separator: ",",
347347
trailing_separator: SeparatorTactic::Never,
348348
indent: arg_indent,

tests/config/small_tabs.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ newline_style = "Unix"
66
fn_brace_style = "SameLineWhere"
77
fn_return_indent = "WithArgs"
88
fn_args_paren_newline = true
9+
fn_args_layout = "Tall"
910
struct_trailing_comma = "Vertical"
1011
struct_lit_trailing_comma = "Vertical"
1112
struct_lit_style = "BlockIndent"

tests/source/fn-custom.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-fn_args_layout: Compressed
2+
// Test some of the ways function signatures can be customised.
3+
4+
// Test compressed layout of args.
5+
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
6+
foo();
7+
}
8+
9+
impl Foo {
10+
fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
11+
foo();
12+
}
13+
}

tests/target/fn-custom.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-fn_args_layout: Compressed
2+
// Test some of the ways function signatures can be customised.
3+
4+
// Test compressed layout of args.
5+
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
6+
d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
7+
foo();
8+
}
9+
10+
impl Foo {
11+
fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
12+
d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
13+
foo();
14+
}
15+
}

0 commit comments

Comments
 (0)