Skip to content

Add test for and fix issue #6927.#6928

Closed
vgaspary wants to merge 2 commits into
rust-lang:mainfrom
vgaspary:ig_item_rustdoc_conflict
Closed

Add test for and fix issue #6927.#6928
vgaspary wants to merge 2 commits into
rust-lang:mainfrom
vgaspary:ig_item_rustdoc_conflict

Conversation

@vgaspary
Copy link
Copy Markdown

@vgaspary vgaspary commented May 25, 2026

The root cause for the issue is that upon flattening an import tree rustfmt repeats the attributes of the original use statement for all the new ones. This makes sense, and in case of #[cfg...] attributes it's essential.

The problem occurs because rustc_ast treats rustdoc comments as attributes too, with the rustc_ast::ast::Attribute type.

Luckily, it has an is_doc_comment function. The fix uses that to partition the attributes into rustdoc comments and the rest, and then clone the rest for all new use statements, while keeping the comments only with the first one.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label May 25, 2026
@vgaspary vgaspary changed the title Add test for issue #6927. Add test for and fix issue #6927. May 26, 2026
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

First, I think we should finish the discussion in #6927 to decide on the behavior before more work is done on this PR.

upon flattening an import tree rustfmt repeats the attributes of the original use statement for all the new ones. This makes sense, and in case of #[cfg...] attributes it's essential.

You acknowledge that the #[cfg...] case is essential, but don't add any test cases for it. Specifically I'd want to see cases where #[cfg] and /// doc comments are used together. Since /// doc comment is just syntax sugar for #[doc = r" This is a doc comment."] I'd also expect to see test cases that use the doc attribute.

View changes since this review

@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 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 26, 2026

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

@ytmimi ytmimi added the S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). label May 26, 2026
@ytmimi
Copy link
Copy Markdown
Contributor

ytmimi commented May 26, 2026

@rustbot author

@vgaspary vgaspary force-pushed the ig_item_rustdoc_conflict branch from 2f39613 to 2698e69 Compare May 26, 2026 22:09
vgaspary added 2 commits May 27, 2026 00:10
rustdoc comments.

`rustc_ast::ast::Attribute` represents both attributes (`#[...]`) and
rustdoc comments (`///...`). When flattening an import tree, it makes
sense to repeat the attributes for each item. Rustdoc comments, however,
don't make sense for each item.

Fixes issue#6927.
@vgaspary vgaspary force-pushed the ig_item_rustdoc_conflict branch from 2698e69 to d974229 Compare May 26, 2026 22:10
@ytmimi
Copy link
Copy Markdown
Contributor

ytmimi commented May 27, 2026

See #6927 (comment)

@ytmimi ytmimi closed this May 27, 2026
@rustbot rustbot removed the S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. label May 27, 2026
@ytmimi ytmimi removed the S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants