Skip to content

update chain handling of long lines and block-like parents #3884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 249 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,255 @@ fn example() {
}
```

## `chains_block_parent_indent_children`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always have such a hard time coming up with config names 😄 If this approach seems viable for handling the scenario in #3157 (and it should indeed be configurable) then this should probably be renamed to something more succinct

Determines whether to indent the child chain items of a chain that begins with a block-like parent element when `indent_style` is `Block`.

- **Default value**: `"OnlyWithParent"`
- **Possible values**: `"Always"`, `"OnlyWithParent"`
- **Stable**: No (tracking issue: ...)

#### `OnlyWithParent` (default):
Only indent the children chain elements of a block-like parent element if the parent's body was indented.

```rust
// chains_block_parent_indent_parent_item: "OnlyTupleLitsAndSimpleCalls"
#![rustfmt::skip]
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.foo()
.aaa_aaa();

let y = if some_condition {
// foo
val1
} else {
// bar
val2
}
.method_call()
.other_call()
.another();
}
```

#### `Always`:
Always indent the children chain elements of a block-like parent element, regardless of whether the parent element body was indented.

```rust
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.foo()
.aaa_aaa();

let y = if some_condition {
// foo
val1
} else {
// bar
val2
}
.method_call()
.other_call()
.another();
}
```

See also: [`indent_style`](#indent_style), [`chains_block_parent_indent_parent_item`](#chains_block_parent_indent_parent_item).

## `chains_block_parent_indent_parent_item`
Determines whether the body of block-like chain parents are indented when `indent_style` is `Block`.

- **Default value**: `"Never"`
- **Possible values**: `"Always"`, `"Never"`, `"OnlySimpleCalls"`, `"OnlyTupleLitsAndSimpleCalls"`
- **Stable**: No (tracking issue: ...)

#### `"Never"` (default):
The body of block-like parent chain elements are never indented.

```rust
#![rustfmt::skip]
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.aaa_aaa()
.do_stuff(
StructB {
test_test_b: other_value,
}
.ddd_ddd()
.eee_eee(),
)
.bbb_bbb()
.ccc_ccc();

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();
}
```

#### `"Always"`:
The body of block-like parent chain elements are always indented.

```rust
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.aaa_aaa()
.do_stuff(
StructB {
test_test_b: other_value,
}
.ddd_ddd()
.eee_eee(),
)
.bbb_bbb()
.ccc_ccc();

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();
}
```

#### `"OnlySimpleCalls"`:
The body of block-like parent chain elements are only indented when the parent is a simple call-like chain item, such as a method call with no multiline block like arguments (like a closure).

```rust
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.aaa_aaa()
.do_stuff(
StructB {
test_test_b: other_value,
}
.ddd_ddd()
.eee_eee(),
)
.bbb_bbb()
.ccc_ccc();

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();
}
```

#### `"OnlyTupleLitsAndSimpleCalls"`:
The body of block-like parent chain elements are only indented when the parent is a tuple literal, or a simple call-like chain item, such as a method call with no multiline block like arguments (like a closure).

```rust
fn example() {
let all = very_very_very_very_very_long_fun_name(
very_very_very_very_very_very_very_very_very_long_var_name,
)
.iter()
.map(|x| x + very_very_very_very_very_very_long_var_name);

StructA {
test_test: some_value,
}
.do_stuff(StructB {
test_test_b: other_value,
})
.aaa_aaa()
.do_stuff(
StructB {
test_test_b: other_value,
}
.ddd_ddd()
.eee_eee(),
)
.bbb_bbb()
.ccc_ccc();

foo(|x| {
// ....
})
.bar()
.baz()
.unwrap();
}
```

See also: [`indent_style`](#indent_style).

## `comment_width`

Maximum length of comments. No effect unless`wrap_comments = true`.
Expand Down
Loading