inconsistent indents on function calls with closure arguments
Open
Nobody has claimed this yet.
A-closures
I-poor-formatting
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Edit (simplified):
Output of rustfmt on nightly-2024-03-08:
fn main() {
app.with_state()
.layer(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
|foo: &Xxxxxxxxx| macroxxxx!(??xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx),
));
}
Expected:
fn main() {
app.with_state()
.layer(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(|foo: &Xxxxxxxxx| {
macroxxxx!(??xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
}));
}
original report
This code:
fn main() {
let app = app
.with_state(build_schema().await)
.layer(TraceLayer::new_for_http().make_span_with(
|req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
));
}
formats to:
❮ rustfmt +nightly-2024-03-08 b.rs --emit stdout
/tmp/ktmp/SgB/b.rs:
fn main() {
let app =
app.with_state(build_schema().await)
.layer(TraceLayer::new_for_http().make_span_with(
|req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
));
}
I think leaving the original code is fine. Or maybe It's ideal to indent the argument one more block like this:
fn main() {
let app =
app.with_state(build_schema().await)
.layer(TraceLayer::new_for_http().make_span_with(
|req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
));
}
because rustfmt emits like so if the argument was normal function call. For example:
❯ rustfmt +nightly-2024-03-08 a.rs --emit stdout
/tmp/ktmp/SgB/a.rs:
fn main() {
let app =
app.with_state(build_schema().await)
.layer(TraceLayer::new_for_http().make_span_with(
sooooooooooooooooooooooooooooooooooooooo_long_function_call_here(foo, bar, baz),
));
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the rustfmt command and the closure-argument examples shown in the issue. Compare formatting for closure arguments with the normal function-call example, then verify that the output matches the expected indentation without regressing the existing formatting behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100