Support non-indented where clauses

This commit is contained in:
Nick Cameron 2015-09-01 18:38:12 +12:00
parent fc2fb8be43
commit 6f3c329500
5 changed files with 32 additions and 2 deletions

View File

@ -91,6 +91,7 @@ create_config! {
fn_args_paren_newline: bool,
fn_args_layout: Density,
fn_arg_indent: BlockIndentStyle,
where_indent: BlockIndentStyle, // Visual will be treated like Tabbed
generics_indent: BlockIndentStyle,
struct_trailing_comma: SeparatorTactic,
struct_lit_trailing_comma: SeparatorTactic,
@ -118,6 +119,7 @@ impl Default for Config {
fn_args_paren_newline: true,
fn_args_layout: Density::Tall,
fn_arg_indent: BlockIndentStyle::Visual,
where_indent: BlockIndentStyle::Tabbed,
generics_indent: BlockIndentStyle::Visual,
struct_trailing_comma: SeparatorTactic::Vertical,
struct_lit_trailing_comma: SeparatorTactic::Vertical,

View File

@ -800,9 +800,14 @@ impl<'a> FmtVisitor<'a> {
return String::new();
}
let extra_indent = match self.config.where_indent {
BlockIndentStyle::Inherit => 0,
BlockIndentStyle::Tabbed | BlockIndentStyle::Visual => config.tab_spaces,
};
let context = self.get_context();
// 6 = "where ".len()
let offset = indent + config.tab_spaces + 6;
let offset = indent + extra_indent + 6;
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,
@ -828,7 +833,7 @@ impl<'a> FmtVisitor<'a> {
};
format!("\n{}where {}",
make_indent(indent + config.tab_spaces),
make_indent(indent + extra_indent),
write_list(&items.collect::<Vec<_>>(), &fmt))
}

View File

@ -8,6 +8,7 @@ fn_return_indent = "WithArgs"
fn_args_paren_newline = true
fn_args_layout = "Tall"
fn_arg_indent = "Visual"
where_indent = "Tabbed"
generics_indent = "Visual"
struct_trailing_comma = "Vertical"
struct_lit_trailing_comma = "Vertical"

View File

@ -1,5 +1,6 @@
// rustfmt-fn_arg_indent: Inherit
// rustfmt-generics_indent: Tabbed
// rustfmt-where_indent: Inherit
// Test different indents.
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
@ -10,6 +11,10 @@ fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb, TTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUU: WW
bar();
}
fn baz() where X: TTTTTTTT {
baz();
}
impl Foo {
fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
foo();
@ -18,6 +23,10 @@ impl Foo {
fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb, TTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW>(a: Aaaaaaaaaaaaaaa) {
bar();
}
fn baz() where X: TTTTTTTT {
baz();
}
}
struct Foo<TTTTTTTTTTTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUU, VVVVVVVVVVVVVVVVVVVVVVVVVVV, WWWWWWWWWWWWWWWWWWWWWWWW> {

View File

@ -1,5 +1,6 @@
// rustfmt-fn_arg_indent: Inherit
// rustfmt-generics_indent: Tabbed
// rustfmt-where_indent: Inherit
// Test different indents.
fn foo(a: Aaaaaaaaaaaaaaa,
@ -17,6 +18,12 @@ fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb,
bar();
}
fn baz()
where X: TTTTTTTT
{
baz();
}
impl Foo {
fn foo(self,
a: Aaaaaaaaaaaaaaa,
@ -33,6 +40,12 @@ impl Foo {
(a: Aaaaaaaaaaaaaaa) {
bar();
}
fn baz()
where X: TTTTTTTT
{
baz();
}
}
struct Foo<TTTTTTTTTTTTTTTTTTTTTTTTTTTT,