rust-lang / rust-lang/rustfmt

Configuration for trailing commas does not affect macros defined with lists

Open
#6,673 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Formatting for vec! macros will always follow a trailing_comma = "Vertical" style. Lists small enough to fit into one line will ignore a setting of "Always", while lists large enough to be displayed vertically will ignore "Never".

With no other configuration changes this code block will always be formatted to the following regardless of the setting for trailing commas:

    let short = vec![1.0, 2.0, 3.0];
    let long = vec![
        1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
        17.0, 18.0, 19.0, 20.0,
    ];

This likely applies to any other macro defined by a list as well, but vec! was what I found the issue with and I'm not sure off the top of my head if there are other macros defined by rust that engage with lists in this way.

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 reproducing the reported vec! formatting with trailing_comma set to "Always", "Never", and "Vertical" in rustfmt. Check whether other list-like macros show the same behavior, and consider the issue done when short and vertically formatted lists consistently follow each setting.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.