rust-lang / rust-lang/rustfmt

Option to split small chains instead of putting on single new line

Open
#3,538 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

My max_width is 80, using stable version of rustfmt.

E.g. this code I would expect to remain as is:

    let resp = req
        .state()
        .db
        .send(msg)
        .from_err()
        .and_then(|db_resp| match db_resp {
            Ok(roles) => Ok(HttpResponse::Created().json(roles)),
            Err(e) => Err(e),
        });

but is instead formatted like this:

    let resp =
        req.state()
            .db
            .send(msg)
            .from_err()
            .and_then(|db_resp| match db_resp {
                Ok(roles) => Ok(HttpResponse::Created().json(roles)),
                Err(e) => Err(e),
            });

Smaller chains are sometimes kept as a single line but put on a new line, like so:

                let login_ids: Vec<_> =
                    result.active_members.iter().map(|m| m.login_id).collect();

It would be great to have an option to specify that I prefer splitting up such chains instead of keeping them together as much as possible. Apologies if there is already an option for this and I've missed it.

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

No source files or tests are named. Reproduce the two formatting examples with rustfmt using max_width 80, then trace the formatting behavior and option configuration; done means a documented option consistently prefers splitting small chains instead of moving the whole chain to a new line.

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.