Skip to content

Add unnecessary_trailing_comma lint - #16530

Merged
Jarcho merged 1 commit into
rust-lang:masterfrom
nyurik:unnecessary_trailing_comma
Feb 23, 2026
Merged

Add unnecessary_trailing_comma lint#16530
Jarcho merged 1 commit into
rust-lang:masterfrom
nyurik:unnecessary_trailing_comma

Conversation

@nyurik

@nyurik nyurik commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

This matches cargo fmt behavior but for format!(...) -style macro calls.

To make this PR easier to review, it moves all linting of the clippy code to #16533

Suggest removing an unnecessary trailing comma before the closing parenthesis in single-line format-like macro invocations (e.g. println!, format!, write!). The lint currently only runs on format-like macros because it relies on format-argument parsing; arbitrary user macros are not supported to avoid incorrect suggestions.

  • Lint is in the style group (allow-by-default)
  • Single-line only: multi-line macro invocations are not linted
  • Machine-applicable fix: removes the trailing comma
// catches this
debug!("Foo={}", 1,);

// suggests this
debug!("Foo={}", 1);

Closes #13965

changelog: [unnecessary_trailing_comma]: new lint to remove trailing commas in a single-line format macro usage

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Feb 7, 2026
@rustbot

rustbot commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from 46ad29b to 0f7b216 Compare February 7, 2026 08:36
@rustbot

This comment has been minimized.

@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from 0f7b216 to f3f0517 Compare February 7, 2026 08:37
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown

Lintcheck changes for f72e055

Lint Added Removed Changed
clippy::unnecessary_trailing_comma 17 0 0

This comment will be updated if you push new changes

@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from f3f0517 to f180a19 Compare February 7, 2026 09:07
@rustbot

rustbot commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in clippy_lints/src/doc

cc @notriddle

Comment thread clippy_lints/src/format_args.rs Outdated
@rustbot

This comment has been minimized.

@samueltardieu

Copy link
Copy Markdown
Member

The style category is warn-by-default. There is a risk that this lint is too opinionated for a warn-by-default category. Also, we don't usually lint for formatting as this is handled by rustfmt.

@nyurik

nyurik commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

@samueltardieu this lint is essentially the missing piece for a single line macro calls that cargo fmt already does for regular function calls. I don't think anyone would ever want to have println!("...",) -- most of these are simply accidental leftovers for when multiline formats get reformatted as a single line. The only reason cargo fmt cannot do it is that it requires type resolution to ensure correct detection. Note that --fix should work perfectly for this lint. I honestly think this is a "style" as anything could possibly get.

@Jarcho

Jarcho commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

pull Bot pushed a commit to Mattlk13/rust-clippy that referenced this pull request Feb 9, 2026
…g#16533)

This noop PR makes the new comma-removing lint PR less noisy, allowing
it focus only on the new functionality

See rust-lang#16530

changelog: none
@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from ccd5535 to 1f35186 Compare February 9, 2026 21:35
@rustbot

This comment has been minimized.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 10, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 10, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 10, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2026
…n, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from 1f35186 to d6d1b45 Compare February 11, 2026 20:44
rust-timer added a commit to rust-lang/rust that referenced this pull request Feb 12, 2026
Rollup merge of #152372 - nyurik:clippy-rustc_trait_selection, r=mati865

style: remove unneeded trailing commas

Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity.

I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
Comment thread clippy_lints/src/format_args.rs Outdated
Comment thread clippy_lints/src/format_args.rs Outdated
Comment thread clippy_lints/src/format_args.rs Outdated
Comment thread clippy_lints/src/format_args.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Feb 13, 2026
@rustbot

rustbot commented Feb 13, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from d6d1b45 to ddde8fe Compare February 13, 2026 22:31
@rustbot

This comment has been minimized.

@nyurik nyurik left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread clippy_lints/src/format_args.rs Outdated
Comment thread clippy_lints/src/format_args.rs Outdated
Comment thread clippy_lints/src/format_args.rs Outdated
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Feb 13, 2026
Comment thread clippy_lints/src/format_args.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Feb 15, 2026
@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from 87d5992 to 3c01f64 Compare February 16, 2026 03:40
@rustbot

This comment has been minimized.

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you squash down the commits please.

View changes since this review

Suggest removing an unnecessary trailing comma before the closing
parenthesis in single-line format-like macro invocations (e.g.
println!, format!, write!). The lint currently only runs on
format-like macros because it relies on format-argument parsing;
arbitrary user macros are not supported to avoid incorrect
suggestions.

- Lint is in the `style` group (allow-by-default)
- Single-line only: multi-line macro invocations are not linted
- Machine-applicable fix: removes the trailing comma
@nyurik
nyurik force-pushed the unnecessary_trailing_comma branch from 3c01f64 to f72e055 Compare February 17, 2026 19:30
@rustbot

rustbot commented Feb 17, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nyurik

nyurik commented Feb 17, 2026

Copy link
Copy Markdown
Contributor Author

thx @Jarcho, rebased and squashed

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho
Jarcho added this pull request to the merge queue Feb 23, 2026
Merged via the queue into rust-lang:master with commit 38321c8 Feb 23, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 23, 2026
@nyurik
nyurik deleted the unnecessary_trailing_comma branch April 16, 2026 17:23
yash-kumarx added a commit to yash-kumarx/rust-clippy that referenced this pull request May 4, 2026
Keep new_instead_of_clear entry and incorporate all lint entries from
master: unnecessary_trailing_comma (pedantic, rust-lang#16530), disallowed_fields,
manual_checked_ops, duration_suboptimal_units, and manual_take.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest to remove unneeded trailing comma

5 participants