Skip to content

fix: don't add trailing comma after .. in struct pattern suggestion#153501

Closed
KernelKraze wants to merge 1 commit intorust-lang:mainfrom
KernelKraze:contribute/fix-dotdot-trailing-comma-suggestion
Closed

fix: don't add trailing comma after .. in struct pattern suggestion#153501
KernelKraze wants to merge 1 commit intorust-lang:mainfrom
KernelKraze:contribute/fix-dotdot-trailing-comma-suggestion

Conversation

@KernelKraze
Copy link

When the last listed field has a trailing comma, the suggestion for
"pattern requires .. due to inaccessible fields" was producing
field, ..,, which doesn't compile.

Before:

help: ignore the inaccessible and unused fields
   |
LL |         visible, ..,
   |                ++++

After:

help: ignore the inaccessible and unused fields
   |
LL |         visible, ..
   |                  ++

Fixes #149787

r? @estebank

Copilot AI review requested due to automatic review settings March 6, 2026 15:20
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2026
@rustbot

This comment has been minimized.

This comment was marked as spam.

…stion

When the last field in the pattern already has a trailing comma, the
suggestion was appending `, ..` after the field span, producing
`field, ..,` which is invalid. Check for an existing comma in the
source and insert ` ..` after it instead.
@KernelKraze KernelKraze force-pushed the contribute/fix-dotdot-trailing-comma-suggestion branch from b38897d to d357f94 Compare March 6, 2026 15:36
@Kivooeo
Copy link
Member

Kivooeo commented Mar 6, 2026

can you please add a test to reflect new behaviour

@estebank
Copy link
Contributor

estebank commented Mar 6, 2026

I'm pretty sure this is already handled in #151280, which is on its way to be merged.

@KernelKraze KernelKraze closed this Mar 6, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect trailing comma suggested in “pattern requires .. due to inaccessible fields” diagnostic for multiline pattern

5 participants