Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,16 +1074,26 @@ fn light_rewrite_comment(
// `*` in `/*`.
let first_non_whitespace = l.find(|c| !char::is_whitespace(c));
let left_trimmed = if let Some(fnw) = first_non_whitespace {
if l.as_bytes()[fnw] == b'*' && fnw > 0 {
&l[fnw - 1..]
if l.as_bytes()[fnw] == b'*' {
Cow::Owned(format!(" {}", &l[fnw..]))
} else {
&l[fnw..]
Cow::Borrowed(&l[fnw..])
}
} else {
""
Cow::Borrowed("")
};

// Preserve markdown's double-space line break syntax in doc comment.
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment)
match left_trimmed {
Cow::Borrowed(left_trimmed) => Cow::Borrowed(trim_end_unless_two_whitespaces(
left_trimmed,
is_doc_comment,
)),
Cow::Owned(left_trimmed) => {
let trimmed = trim_end_unless_two_whitespaces(&left_trimmed, is_doc_comment);
Cow::Owned(trimmed.to_string())
}
}
})
.join(&format!("\n{}", offset.to_string(config)))
}
Expand Down
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>,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
*/
mod foo {}
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>,
}
}
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> {}
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>,
}
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>,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
*/
mod foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**First comment.
*
*/
pub mod outer {
/**Second comment.
foo
*/
Comment on lines +5 to +7

@ytmimi ytmimi Aug 22, 2026

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.

hmm things didn't get aligned in this case. Was that expected?

View changes since the review

Copy link
Copy Markdown
Member Author

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

@jieyouxu jieyouxu Sep 1, 2026

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member Author

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.

pub struct Inner {
/**Third comment.
*/
pub octets: Vec<u8>,
}
}
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> {}
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>,
}