rust-lang / rust-lang/rustfmt

Feature request: Specify priority of small heuristics / line-breaking rules

Open
#6,057 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

I have noticed that rustfmt seems to prioritize breaking chains before it'll break on function arguments.

For example:

let value =
    obj.func(&long_struct.arg1, long_struct.arg2, long_struct.arg3, true);

is preferred instead of:

let value = obj.func(
    &long_struct.arg1,
    long_struct.arg2,
    long_struct.arg3,
    true,
);

I have tried so hard to find configuration settings that will prefer the second style when a line is too long (according to max_width, chain_width, or fn_call_width). A quick way to see this behavior is to set all 3 of these config values to the same number (80).

Could a new config option be introduced (perhaps called small_heuristics_priority) that takes an array of the names of the other options in the order that they should be applied to fix the line?

small_heuristics_priority = [ "fn_call_width", "chain_width" ]

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

Start by tracing how rustfmt applies max_width, chain_width, and fn_call_width when formatting the examples. Review the existing TOML configuration handling and related formatting tests, if present. Done means a documented priority setting can select the requested function-argument-first behavior and the examples format accordingly.

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.