Skip to content

Commit dbd8936

Browse files
scampitopecongiro
authored andcommitted
fix rust code in comment with a line containing only a hash sign (#3818)
1 parent f4bc494 commit dbd8936

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/comment.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ fn rewrite_comment_inner(
823823
const RUSTFMT_CUSTOM_COMMENT_PREFIX: &str = "//#### ";
824824

825825
fn hide_sharp_behind_comment(s: &str) -> Cow<'_, str> {
826-
if s.trim_start().starts_with("# ") {
826+
let s_trimmed = s.trim();
827+
if s_trimmed.starts_with("# ") || s_trimmed == "#" {
827828
Cow::from(format!("{}{}", RUSTFMT_CUSTOM_COMMENT_PREFIX, s))
828829
} else {
829830
Cow::from(s)

tests/source/issue-3751.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-format_code_in_doc_comments: true
2+
3+
//! Empty pound line
4+
//!
5+
//! ```rust
6+
//! #
7+
//! # fn main() {
8+
//! foo ( ) ;
9+
//! # }
10+
//! ```

tests/target/issue-3751.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-format_code_in_doc_comments: true
2+
3+
//! Empty pound line
4+
//!
5+
//! ```rust
6+
//! #
7+
//! # fn main() {
8+
//! foo();
9+
//! # }
10+
//! ```

0 commit comments

Comments
 (0)