Leave wrapped struct/function as is even not touch the max_width
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
With vscode extension rust-analyzer, the (visual) line width in editor might not the same as the width in text file.
e.g.
fn f(very_very_very_very_long_arg_1: i32, very_very_very_very_long_arg_2: i32) {}
fn main() {
f("1".parse().expect("true"), "2".parse().expect("true")); // what rustfmt see
}
with rust-analyzer it would be rendered as
fn main() {
f(very_very_very_very_long_arg_1: "1".parse().expect("true"), very_very...: "2".parse().expect("true")); // what we see
}
which is much longer.
The question here is not that rustfmt would not turn this f("1".parse().expect("true"), "2".parse().expect("true")); into vertical format, it is about rustfmt would shrink my vertical formatting version into oneline.
// I write it vertically, after `cargo fmt` it would be forced be into one line
fn main() {
f(
"1".parse().expect("true"),
"2".parse().expect("true"),
);
}
I think we should add an option like no_force_same_line that rustfmt would only break long line but not combine lines, so that when I explicitly write vertical formatting code, rustfmt would leave it as is.
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
The issue provides no file or test entry point; begin by tracing rustfmt's handling of explicitly vertical function-call arguments and wrapped structs. The change would be complete when long lines still break, while user-written vertical formatting is not recombined into one line, with tests covering the proposed option and the examples described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100