-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix non-idempotent block doc comment closer rewrite #7017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ytmimi
merged 4 commits into
rust-lang:main
from
jieyouxu:jieyouxu/fix/non-idempotent-block-doc-comment
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1595b5e
[Test] Add failing regression test for non-idempotent block doc comments
jieyouxu 44ca78d
[Comment] Make block doc comment closer rewrite idempotent
jieyouxu d8d6a47
[Test] Demonstrate a stable default formatting change
jieyouxu 892ea2c
[Test] Demonstrate `rustc` block doc comment alignment changes
jieyouxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/source/6639-non-idempotent-block-doc-comments/inner-block-doc-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /*!First comment. | ||
| */ | ||
| pub mod outer { | ||
| /*!Second comment. | ||
| */ | ||
| pub struct Inner { | ||
| pub octets: Vec<u8>, | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
tests/source/6639-non-idempotent-block-doc-comments/naive-outer-block-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /** | ||
| */ | ||
| mod foo {} |
13 changes: 13 additions & 0 deletions
13
tests/source/6639-non-idempotent-block-doc-comments/outer-block-doc-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /**First comment. | ||
| * | ||
| */ | ||
| pub mod outer { | ||
| /**Second comment. | ||
| foo | ||
| */ | ||
| pub struct Inner { | ||
| /**Third comment. | ||
| */ | ||
| pub octets: Vec<u8>, | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
tests/source/6639-non-idempotent-block-doc-comments/rustc-sample-1.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! Sample from | ||
| //! <https://github.com/rust-lang/rust/blob/70222712809cd5cc1718ed8995914a1cbacb6b92/compiler/rustc_codegen_llvm/src/common.rs#L69-L93>. | ||
|
|
||
| pub(crate) fn placeholder() {} | ||
|
|
||
| /* | ||
| * A note on nomenclature of linking: "extern", "foreign", and "upcall". | ||
| * | ||
| * An "extern" is an LLVM symbol we wind up emitting an undefined external | ||
| * reference to. This means "we don't have the thing in this compilation unit, | ||
| * please make sure you link it in at runtime". This could be a reference to | ||
| * C code found in a C library, or rust code found in a rust crate. | ||
| * | ||
| * Most "externs" are implicitly declared (automatically) as a result of a | ||
| * user declaring an extern _module_ dependency; this causes the rust driver | ||
| * to locate an extern crate, scan its compilation metadata, and emit extern | ||
| * declarations for any symbols used by the declaring crate. | ||
| * | ||
| * A "foreign" is an extern that references C (or other non-rust ABI) code. | ||
| * There is no metadata to scan for extern references so in these cases either | ||
| * a header-digester like bindgen, or manual function prototypes, have to | ||
| * serve as declarators. So these are usually given explicitly as prototype | ||
| * declarations, in rust code, with ABI attributes on them noting which ABI to | ||
| * link via. | ||
| * | ||
| * An "upcall" is a foreign call generated by the compiler (not corresponding | ||
| * to any user-written call in the code) into the runtime library, to perform | ||
| * some helper task such as bringing a task to life, allocating memory, etc. | ||
| * | ||
| */ | ||
|
|
||
| /// A structure representing an active landing pad for the duration of a basic | ||
| /// block. | ||
| pub(crate) struct Funclet<'ll> {} |
24 changes: 24 additions & 0 deletions
24
tests/source/6639-non-idempotent-block-doc-comments/rustc-sample-2.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //! Taken from | ||
| //! <https://github.com/rust-lang/rust/blob/70222712809cd5cc1718ed8995914a1cbacb6b92/compiler/rustc_mir_transform/src/inline.rs#L1166-L1186>. | ||
|
|
||
| /** | ||
| * Integrator. | ||
| * | ||
| * Integrates blocks from the callee function into the calling function. | ||
| * Updates block indices, references to locals and other control flow | ||
| * stuff. | ||
| */ | ||
| struct Integrator<'a, 'tcx> { | ||
| args: &'a [Local], | ||
| new_locals: RangeFrom<Local>, | ||
| new_scopes: RangeFrom<SourceScope>, | ||
| new_blocks: RangeFrom<BasicBlock>, | ||
| destination: Local, | ||
| callsite_scope: SourceScopeData<'tcx>, | ||
| callsite: &'a CallSite<'tcx>, | ||
| cleanup_block: UnwindAction, | ||
| in_cleanup_block: bool, | ||
| return_block: Option<BasicBlock>, | ||
| tcx: TyCtxt<'tcx>, | ||
| always_live_locals: DenseBitSet<Local>, | ||
| } |
9 changes: 9 additions & 0 deletions
9
tests/target/6639-non-idempotent-block-doc-comments/inner-block-doc-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /*!First comment. | ||
| */ | ||
| pub mod outer { | ||
| /*!Second comment. | ||
| */ | ||
| pub struct Inner { | ||
| pub octets: Vec<u8>, | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
tests/target/6639-non-idempotent-block-doc-comments/naive-outer-block-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /** | ||
| */ | ||
| mod foo {} |
13 changes: 13 additions & 0 deletions
13
tests/target/6639-non-idempotent-block-doc-comments/outer-block-doc-comment.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /**First comment. | ||
| * | ||
| */ | ||
| pub mod outer { | ||
| /**Second comment. | ||
| foo | ||
| */ | ||
| pub struct Inner { | ||
| /**Third comment. | ||
| */ | ||
| pub octets: Vec<u8>, | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
tests/target/6639-non-idempotent-block-doc-comments/rustc-sample-1.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! Sample from | ||
| //! <https://github.com/rust-lang/rust/blob/70222712809cd5cc1718ed8995914a1cbacb6b92/compiler/rustc_codegen_llvm/src/common.rs#L69-L93>. | ||
|
|
||
| pub(crate) fn placeholder() {} | ||
|
|
||
| /* | ||
| * A note on nomenclature of linking: "extern", "foreign", and "upcall". | ||
| * | ||
| * An "extern" is an LLVM symbol we wind up emitting an undefined external | ||
| * reference to. This means "we don't have the thing in this compilation unit, | ||
| * please make sure you link it in at runtime". This could be a reference to | ||
| * C code found in a C library, or rust code found in a rust crate. | ||
| * | ||
| * Most "externs" are implicitly declared (automatically) as a result of a | ||
| * user declaring an extern _module_ dependency; this causes the rust driver | ||
| * to locate an extern crate, scan its compilation metadata, and emit extern | ||
| * declarations for any symbols used by the declaring crate. | ||
| * | ||
| * A "foreign" is an extern that references C (or other non-rust ABI) code. | ||
| * There is no metadata to scan for extern references so in these cases either | ||
| * a header-digester like bindgen, or manual function prototypes, have to | ||
| * serve as declarators. So these are usually given explicitly as prototype | ||
| * declarations, in rust code, with ABI attributes on them noting which ABI to | ||
| * link via. | ||
| * | ||
| * An "upcall" is a foreign call generated by the compiler (not corresponding | ||
| * to any user-written call in the code) into the runtime library, to perform | ||
| * some helper task such as bringing a task to life, allocating memory, etc. | ||
| * | ||
| */ | ||
|
|
||
| /// A structure representing an active landing pad for the duration of a basic | ||
| /// block. | ||
| pub(crate) struct Funclet<'ll> {} |
24 changes: 24 additions & 0 deletions
24
tests/target/6639-non-idempotent-block-doc-comments/rustc-sample-2.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //! Taken from | ||
| //! <https://github.com/rust-lang/rust/blob/70222712809cd5cc1718ed8995914a1cbacb6b92/compiler/rustc_mir_transform/src/inline.rs#L1166-L1186>. | ||
|
|
||
| /** | ||
| * Integrator. | ||
| * | ||
| * Integrates blocks from the callee function into the calling function. | ||
| * Updates block indices, references to locals and other control flow | ||
| * stuff. | ||
| */ | ||
| struct Integrator<'a, 'tcx> { | ||
| args: &'a [Local], | ||
| new_locals: RangeFrom<Local>, | ||
| new_scopes: RangeFrom<SourceScope>, | ||
| new_blocks: RangeFrom<BasicBlock>, | ||
| destination: Local, | ||
| callsite_scope: SourceScopeData<'tcx>, | ||
| callsite: &'a CallSite<'tcx>, | ||
| cleanup_block: UnwindAction, | ||
| in_cleanup_block: bool, | ||
| return_block: Option<BasicBlock>, | ||
| tcx: TyCtxt<'tcx>, | ||
| always_live_locals: DenseBitSet<Local>, | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm things didn't get aligned in this case. Was that expected?
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, let me double check
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% if this is the intended alignment per se, but at least the stable formatting is also not aligned (versus when there's a continuing
*)rustfmt 1.9.0-stable (88d9e12ae1 2026-08-18):$ rustfmt +stable foo.rs --check --config-path=/dev/null Diff in /home/joe/repos/rustfmt/foo.rs:3: */ pub mod outer { /**Second comment. -foo -*/ + foo + */ pub struct Inner { /**Third comment. -*/ + */ pub octets: Vec<u8>, } }The second comment case is idempotent for stable/nightly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled this out to #7109.