Support where clause predicates at different indentations

This commit is contained in:
Nick Cameron 2015-09-01 19:04:41 +12:00
parent 02a01350ff
commit 6216dce14e
7 changed files with 47 additions and 2 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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"

View File

@ -0,0 +1,6 @@
// rustfmt-where_pred_indent: Tabbed
// Test different indents.
fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT {
baz();
}

View File

@ -0,0 +1,6 @@
// rustfmt-where_pred_indent: Inherit
// Test different indents.
fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT {
baz();
}

View File

@ -0,0 +1,11 @@
// rustfmt-where_pred_indent: Tabbed
// Test different indents.
fn qux()
where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT
{
baz();
}

View File

@ -0,0 +1,11 @@
// rustfmt-where_pred_indent: Inherit
// Test different indents.
fn qux()
where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT
{
baz();
}