Skip to content

fix: preserve comments after imports - #7126

Closed
efegokdemir wants to merge 1 commit into
rust-lang:mainfrom
efegokdemir:codex/issue-7051-preserve-import-comments
Closed

efegokdemir wants to merge 1 commit into
rust-lang:mainfrom
efegokdemir:codex/issue-7051-preserve-import-comments

Conversation

@efegokdemir

Copy link
Copy Markdown

Summary

Preserve comments placed between a top-level use path and its terminating semicolon. Rustfmt was reconstructing the import from the AST path and dropping these comments.

Changes

  • Carry the complete top-level import span through formatting.
  • Recover trailing block and line comments before the semicolon using the existing comment-combination logic.
  • Added regression fixtures for both comment forms.

Testing

  • cargo fmt -- --check
  • git diff --check
  • cargo test --locked ⚠️ blocked before tests because the environment lacks the pinned nightly toolchain's rustc-dev and internal compiler crates (rustc_ast, rustc_driver, and related components).

Notes

The recovery is limited to comments not already present in the reconstructed import, so nested import comment handling remains unchanged. The issue's maintainer indicated that LLM assistance is permitted for this contribution; the implementation and PR description have been reviewed manually.

Signed-off-by: Efe Gökdemir <efe@rexcode.co.uk>
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Sep 20, 2026
@ytmimi ytmimi self-assigned this Sep 20, 2026

@ytmimi ytmimi 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.

@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 Sep 20, 2026
@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #7127) made this pull request unmergeable. Please resolve the merge conflicts.

@jieyouxu jieyouxu closed this Sep 22, 2026
@rustbot rustbot removed the S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. label Sep 22, 2026
@jieyouxu

Copy link
Copy Markdown
Member

Moderation note: #7129 (comment)

@rust-lang rust-lang locked and limited conversation to collaborators Sep 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants