Skip to content
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

Clarify muliti-line chain elements #163

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 21 additions & 17 deletions guide/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,33 +441,37 @@ x.baz?
let foo = x
.baz?
.qux();

foo(
expr1,
expr2,
).baz?
.qux();
```

#### Multi-line elements

If any element in a chain is formatted across multiple lines, then that element
and any later elements must be on their own line. Earlier elements may be kept
on a single line. E.g.,
If any element in a chain is formatted across multiple lines, then any
following elements must be on their own line. Earlier elements may be kept on a
single line. E.g.,

```rust
a.b.foo(|arg| {
a_stmt;
another_stmt;
})
.bar
.baz
```

The elements following the mulit-line element are indented to match the start
of the mutli-line element.

```rust
a.b.c()?.d
.foo(
an_expr,
another_expr,
)
a.b.c()
.d
.foo(|arg| {
a_stmt;
another_stmt;
})
.bar
.baz
```

Note there is block indent due to the chain and the function call in the above
example.

Prefer formatting the whole chain in multi-line style and each element on one
line, rather than putting some elements on multiple lines and some on a single
line, e.g.,
Expand Down