rust-lang / rust-lang/rustfmt

Trailing comma removed from multiline attribute

Open
#3,277 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macros E-help-wanted I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

I originally had an overly long attribute like this:

#![allow(clippy::needless_pass_by_value, clippy::new_ret_no_self, clippy::new_without_default_derive)]

This got formatted to:

#![allow(
    clippy::needless_pass_by_value,
    clippy::new_ret_no_self,
    clippy::new_without_default_derive
)]

I manually added a comma after the third line, because I expect this list to change in the future.

Expected behavior:

rustfmt keeps the trailing comma.

Actual behavior:

rustfmt removes the trailing comma.


Note that, ideally (IMO), rustfmt would have automatically inserted a trailing comma, or had a setting to specify that behavior. However I don't know if there are situation where the lack of (or presence) of a trailing comma is of semantic significance in (custom) attributes.

If a trailing comma can be significant it should be neither added nor removed automatically, I think. (Unless rustfmt recognizes the specific attribute).

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

Reproduce the issue in rustfmt using the multiline Rust attribute shown in the report, and compare the formatted output with the manually added trailing comma. Determine whether trailing commas in custom attributes can be changed safely, then verify that the final behavior matches the expected or documented policy.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.