Skip to content

Don't duplicate separators when there is a comment before and after a list separator - #7091

Open
randomPoison wants to merge 1 commit into
rust-lang:mainfrom
randomPoison:comments-around-separator
Open

Don't duplicate separators when there is a comment before and after a list separator#7091
randomPoison wants to merge 1 commit into
rust-lang:mainfrom
randomPoison:comments-around-separator

Conversation

@randomPoison

Copy link
Copy Markdown
Contributor

This PR addresses the following issues:

This fix relates to the list formatting machinery in lists.rs, specifically the way that the post-snippet for a list item is parsed in order to extract comments. In the case where there is a comment both before and after a separator in a list, get_comment_end would include the entire gap between the items as the post-snippet of the preceding item. This means that the separator gets included in the post-comment of the preceding item. When write_list then lays out the pieces of the list, it prints a separator and then the entire post-comment, which duplicates the separator.

There are two related fixes for this behavior:

  • Update get_comment_end to split the post-snippet at the separator if there are comments before and after the separator. This means that the comment before the separator becomes the post-comment of the preceding item, and the comment after the separator becomes the pre-comment for the following item.
  • Update extract_post_comment to handle a separator in the middle of the final item's post-snippet. This is necessary because the new splitting rule in get_comment_end doesn't apply the snippet following the final item, since there's no subsequent item to own the comment that follows the separator. To handle this case, we just remove the separator from the post-snippet, which then allows write_list to lay out the separator before the post-comment.

I added a test to cover the cases described in #6759 and #6797.

LLM Usage Disclosure

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

I used an LLM, specifically gpt-5.6 Sol, as a coding aid while working on this fix:

  • The initial changes to extract_post_comment were written by LLM and then heavily rewritten by me. The only thing LLM-written that stayed verbatim is the logic for extracting the separator from the post-snippet.

…ator

- Update get_comment_end to split the post-snippet at the separator if there are comments before and after the separator.
- Update extract_post_comment to handle a separator in the middle of the final item's post-snippet, since the final item has special handling.
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comma gets duplicated in a macro params, obstructed by inline comments

2 participants