Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8f7a047

Browse files
committed
handle lines prefixed with a # inside code blocks
1 parent 78d9091 commit 8f7a047

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/comment.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,16 @@ fn trim_custom_comment_prefix(s: &str) -> String {
752752
.map(|line| {
753753
let left_trimmed = line.trim_left();
754754
if left_trimmed.starts_with(RUSTFMT_CUSTOM_COMMENT_PREFIX) {
755-
left_trimmed.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX)
755+
let orig = left_trimmed.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX);
756+
// due to comment wrapping, a line that was originaly behind `#` is split over
757+
// multiple lines, which needs then to be prefixed with a `#`
758+
if !orig.trim_left().starts_with("# ") {
759+
format!("# {}", orig)
760+
} else {
761+
orig.to_string()
762+
}
756763
} else {
757-
line
764+
line.to_string()
758765
}
759766
})
760767
.collect::<Vec<_>>()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-max_width: 79
2+
// rustfmt-wrap_comments: true
3+
4+
/// ```rust
5+
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd)not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
6+
///
7+
/// // Est lectus hendrerit lorem, eget dignissim orci nisl sit amet massa. Etiam volutpat lobortis eros.
8+
/// let x = 42;
9+
/// ```
10+
fn func() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-max_width: 79
2+
// rustfmt-wrap_comments: true
3+
4+
/// ```rust
5+
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature,
6+
/// # stdsimd)not(dox), feature(cfg_target_feature, target_feature,
7+
/// # stdsimd))]
8+
///
9+
/// // Est lectus hendrerit lorem, eget dignissim orci nisl sit amet massa.
10+
/// // Etiam volutpat lobortis eros.
11+
/// let x = 42;
12+
/// ```
13+
fn func() {}

0 commit comments

Comments
 (0)