Skip to content
Open
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,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>,
}
}