rust-lang / rust-lang/rustfmt

Leave wrapped struct/function as is even not touch the max_width

Open
#6,122 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.