diff --git a/src/config.rs b/src/config.rs index 4779d0e9b98..02076174482 100644 --- a/src/config.rs +++ b/src/config.rs @@ -218,8 +218,10 @@ create_config! { ideal_width: usize, "Ideal width of each line (only used for comments)", leeway: usize, "Leeway of line width (deprecated)", tab_spaces: usize, "Number of spaces per tab", - list_width: usize, "Maximum width in a struct literal or function \ - call before faling back to vertical formatting", + fn_call_width: usize, "Maximum width of the args of a function call\ + before faling back to vertical formatting", + struct_lit_width: usize, "Maximum width in the body of a struct lit\ + before faling back to vertical formatting", newline_style: NewlineStyle, "Unix or Windows line endings", fn_brace_style: BraceStyle, "Brace style for functions", fn_return_indent: ReturnIndent, "Location of return type in function declaration", @@ -258,7 +260,8 @@ impl Default for Config { ideal_width: 80, leeway: 5, tab_spaces: 4, - list_width: 50, + fn_call_width: 50, + struct_lit_width: 12, newline_style: NewlineStyle::Unix, fn_brace_style: BraceStyle::SameLineWhere, fn_return_indent: ReturnIndent::WithArgs, diff --git a/src/expr.rs b/src/expr.rs index 79e03e644e4..f2e6b1e0dfa 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1226,11 +1226,15 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext, span_after(span, "{", context.codemap), span.hi); - let tactic = match (context.config.struct_lit_style, fields.len()) { + let mut tactic = match (context.config.struct_lit_style, fields.len()) { (StructLitStyle::Visual, 1) => ListTactic::HorizontalVertical, _ => context.config.struct_lit_multiline_style.to_list_tactic(), }; + if tactic == ListTactic::HorizontalVertical && fields.len() > 1 { + tactic = ListTactic::LimitedHorizontalVertical(context.config.struct_lit_width); + } + let fmt = ListFormatting { tactic: tactic, separator: ",", diff --git a/src/lists.rs b/src/lists.rs index ef3372bf0b6..c372be2fe8f 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -62,7 +62,7 @@ pub struct ListFormatting<'a> { impl<'a> ListFormatting<'a> { pub fn for_fn(width: usize, offset: Indent, config: &'a Config) -> ListFormatting<'a> { ListFormatting { - tactic: ListTactic::LimitedHorizontalVertical(config.list_width), + tactic: ListTactic::LimitedHorizontalVertical(config.fn_call_width), separator: ",", trailing_separator: SeparatorTactic::Never, indent: offset,