mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Support where clause predicates at different indentations
This commit is contained in:
parent
02a01350ff
commit
6216dce14e
@ -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,
|
||||
|
12
src/items.rs
12
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,
|
||||
|
@ -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"
|
||||
|
6
tests/source/fn-custom-4.rs
Normal file
6
tests/source/fn-custom-4.rs
Normal 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();
|
||||
}
|
6
tests/source/fn-custom-5.rs
Normal file
6
tests/source/fn-custom-5.rs
Normal 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();
|
||||
}
|
11
tests/target/fn-custom-4.rs
Normal file
11
tests/target/fn-custom-4.rs
Normal 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();
|
||||
}
|
11
tests/target/fn-custom-5.rs
Normal file
11
tests/target/fn-custom-5.rs
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user