Skip to content

Include trailing comma in single param vertical fn#6890

Open
jasonaowen wants to merge 1 commit into
rust-lang:mainfrom
jasonaowen:fn_params_layout-vertical-single-arg-trailing-comma
Open

Include trailing comma in single param vertical fn#6890
jasonaowen wants to merge 1 commit into
rust-lang:mainfrom
jasonaowen:fn_params_layout-vertical-single-arg-trailing-comma

Conversation

@jasonaowen
Copy link
Copy Markdown

When formatting a function with a single parameter with fn_params_layout set to Vertical, the previous tactic would remove any trailing commas before spilling to multiple lines for other reasons, such as long function names or return types. Instead, use the same tactic as Tall does, so that the trailing comma is kept if the end result spans multiple lines.

Resolves #6889 fn_params_layout = "Vertical" removes single argument's trailing comma

When formatting a function with a single parameter with
`fn_params_layout` set to `Vertical`, the previous tactic would remove
any trailing commas before spilling to multiple lines for other reasons,
such as long function names or return types. Instead, use the same
tactic as `Tall` does, so that the trailing comma is kept if the end
result spans multiple lines.

Issue rust-lang#6889 `fn_params_layout = "Vertical"` removes single argument's
            trailing comma
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label May 10, 2026
@jieyouxu jieyouxu added SO-fn_params_layout Stable option: fn_params_layout F-impacts-stable-formatted-code Expected formatting impact: affects stable formatted code (caution) F-impacts-stable-options Expected formatting impact: impacts stable options (caution) release-notes Needs an associated changelog entry B-next-style-edition-gate Blocked: can only be done over a style edition; needs a style edition gate labels May 30, 2026
Copy link
Copy Markdown
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks. Considering

  • Self-consistency with fn_params_layout = "Tall" which already adds trailing commas for single param fn, and
  • Inserting a trailing comma is generally better for minimizing extra diff lines

This makes sense to me. However, I think the fix needs to be gated behind a style edition.

View changes since this review

Comment thread src/config/options.rs
match self {
Density::Compressed => ListTactic::Mixed,
Density::Tall => ListTactic::HorizontalVertical,
Density::Vertical if len == 1 => ListTactic::Horizontal,
Copy link
Copy Markdown
Member

@jieyouxu jieyouxu May 30, 2026

Choose a reason for hiding this comment

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

Problem: AFAICT, fn_params_layout is a stable option and fn_params_layout = "Vertical" is a stable value. This means that to uphold rustfmt's strict formatting stability guarantees, I believe this change needs to be gated behind the next style edition.

Can you:

  • Gate this change behind the next style edition + keep the old format intact for previous style editions
  • Add a second copy of fn_params_layout/vertical.rs test (vertical_style_2027.rs or sth) that specifies // rustfmt-style_edition: 2027 + // rustfmt-fn_params_layout: Vertical which demonstrates the "fixed" formatting, but also demonstrating that the previous formatting remains unchanged?

@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels May 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 30, 2026

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

@jieyouxu jieyouxu self-assigned this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-next-style-edition-gate Blocked: can only be done over a style edition; needs a style edition gate F-impacts-stable-formatted-code Expected formatting impact: affects stable formatted code (caution) F-impacts-stable-options Expected formatting impact: impacts stable options (caution) release-notes Needs an associated changelog entry S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. SO-fn_params_layout Stable option: fn_params_layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fn_params_layout = "Vertical" removes single argument's trailing comma

3 participants