diff --git a/src/config.rs b/src/config.rs index b788052a047..12dfce4de33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -93,6 +93,7 @@ create_config! { fn_arg_indent: BlockIndentStyle, where_indent: BlockIndentStyle, // Visual will be treated like Tabbed where_layout: ListTactic, + where_pred_indent: BlockIndentStyle, generics_indent: BlockIndentStyle, struct_trailing_comma: SeparatorTactic, struct_lit_trailing_comma: SeparatorTactic, @@ -122,6 +123,7 @@ impl Default for Config { fn_arg_indent: BlockIndentStyle::Visual, where_indent: BlockIndentStyle::Tabbed, where_layout: ListTactic::Vertical, + where_pred_indent: BlockIndentStyle::Visual, generics_indent: BlockIndentStyle::Visual, struct_trailing_comma: SeparatorTactic::Vertical, struct_lit_trailing_comma: SeparatorTactic::Vertical, diff --git a/src/items.rs b/src/items.rs index d2265fe9db1..b93db659eba 100644 --- a/src/items.rs +++ b/src/items.rs @@ -806,8 +806,16 @@ impl<'a> FmtVisitor<'a> { }; let context = self.get_context(); - // 6 = "where ".len() - let offset = indent + extra_indent + 6; + + let offset = match self.config.where_pred_indent { + BlockIndentStyle::Inherit => indent + extra_indent, + BlockIndentStyle::Tabbed => indent + extra_indent + config.tab_spaces, + // 6 = "where ".len() + BlockIndentStyle::Visual => indent + extra_indent + 6, + }; + // FIXME: if where_pred_indent != Visual, then the budgets below might + // be out by a char or two. + let budget = self.config.ideal_width + self.config.leeway - offset; let span_start = span_for_where_pred(&where_clause.predicates[0]).lo; let items = itemize_list(self.codemap, diff --git a/tests/config/small_tabs.toml b/tests/config/small_tabs.toml index 21d12c7d4ea..912638c91f8 100644 --- a/tests/config/small_tabs.toml +++ b/tests/config/small_tabs.toml @@ -10,6 +10,7 @@ fn_args_layout = "Tall" fn_arg_indent = "Visual" where_indent = "Tabbed" where_layout = "Vertical" +where_pred_indent = "Visual" generics_indent = "Visual" struct_trailing_comma = "Vertical" struct_lit_trailing_comma = "Vertical" diff --git a/tests/source/fn-custom-4.rs b/tests/source/fn-custom-4.rs new file mode 100644 index 00000000000..0293f1b1959 --- /dev/null +++ b/tests/source/fn-custom-4.rs @@ -0,0 +1,6 @@ +// rustfmt-where_pred_indent: Tabbed +// Test different indents. + +fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT { + baz(); +} diff --git a/tests/source/fn-custom-5.rs b/tests/source/fn-custom-5.rs new file mode 100644 index 00000000000..98f11a72eab --- /dev/null +++ b/tests/source/fn-custom-5.rs @@ -0,0 +1,6 @@ +// rustfmt-where_pred_indent: Inherit +// Test different indents. + +fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT { + baz(); +} diff --git a/tests/target/fn-custom-4.rs b/tests/target/fn-custom-4.rs new file mode 100644 index 00000000000..e1da6524565 --- /dev/null +++ b/tests/target/fn-custom-4.rs @@ -0,0 +1,11 @@ +// rustfmt-where_pred_indent: Tabbed +// Test different indents. + +fn qux() + where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT +{ + baz(); +} diff --git a/tests/target/fn-custom-5.rs b/tests/target/fn-custom-5.rs new file mode 100644 index 00000000000..08c717538f2 --- /dev/null +++ b/tests/target/fn-custom-5.rs @@ -0,0 +1,11 @@ +// rustfmt-where_pred_indent: Inherit +// Test different indents. + +fn qux() + where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT +{ + baz(); +}