Skip to content

fix(imports): keep comments before the semicolon in use statements - #7175

Open
Andrew-Velox wants to merge 2 commits into
rust-lang:mainfrom
Andrew-Velox:fix-7051
Open

Andrew-Velox wants to merge 2 commits into
rust-lang:mainfrom
Andrew-Velox:fix-7051

Conversation

@Andrew-Velox

@Andrew-Velox Andrew-Velox commented Oct 10, 2026 •

Copy link
Copy Markdown

Fixes: #7051

Keeps comments before the trailing semicolon of a use item, which were previously being dropped.

Example

use std /* goodbye */; 
use std // bye
;

Changes

  • Added comment recovery logic to top-level use statements to stop dropping comments before trailing semicolons.
  • Added regression tests in tests/source/issue-7051.rs & tests/target/issue-7051.rs.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

I used a local LLM to navigate the codebase and guide me through running tests for different edge cases, as this is my first contribution to the repository.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Oct 10, 2026
@jieyouxu jieyouxu self-assigned this Oct 14, 2026
@jieyouxu jieyouxu added A-comments Area: comments A-imports Area: imports, e.g. `use` syntax X-untriaged-formatting-impact Expected formatting impact: unclear, needs further triage labels Oct 14, 2026

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. Some things.

View changes since this review

Comment thread tests/source/issue-7051.rs Resolved
Comment thread tests/source/issue-7051.rs Resolved
Comment thread src/imports.rs Resolved
Comment thread tests/source/issue-7051.rs Resolved
Comment thread src/imports.rs Resolved
@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 Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

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

Comment thread src/imports.rs

@jieyouxu jieyouxu Oct 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewer note: check formatting impact here, this will impact stable default formatting but it prevents comment loss.

View changes since the review

@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@Andrew-Velox

Copy link
Copy Markdown
Author

I added all of your test cases, including copies within a mod x { }. I renamed opt_hi to commented_span, and it now holds a Span. I left opt_lo as it is because it was like that before. And I used span_before_last instead of BytePos(1) now. The width of ; and the indent are now counted.

@Andrew-Velox

Copy link
Copy Markdown
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2026
@jieyouxu jieyouxu added X-impacts-stable-default-format Expected formatting impact: affects stable default format configuration (caution) and removed X-untriaged-formatting-impact Expected formatting impact: unclear, needs further triage labels Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-comments Area: comments A-imports Area: imports, e.g. `use` syntax S-waiting-on-review Status: awaiting review from the assignee but also interested parties. X-impacts-stable-default-format Expected formatting impact: affects stable default format configuration (caution)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

removes comment after import

3 participants