]> git.lizzy.rs Git - rust.git/commitdiff
handle lines prefixed with a # inside code blocks
authorStéphane Campinas <stephane.campinas@gmail.com>
Sat, 13 Oct 2018 07:57:43 +0000 (09:57 +0200)
committerStéphane Campinas <stephane.campinas@gmail.com>
Sat, 13 Oct 2018 07:57:43 +0000 (09:57 +0200)
src/comment.rs
tests/source/wrapped_hidden_code_block.rs [new file with mode: 0644]
tests/target/wrapped_hidden_code_block.rs [new file with mode: 0644]

index 213879e50a1948a0fef958fa194c9aafa8581920..c946cc6e1c013e0a534b2408186a8cf84e7ca8ce 100644 (file)
@@ -752,9 +752,16 @@ fn trim_custom_comment_prefix(s: &str) -> String {
         .map(|line| {
             let left_trimmed = line.trim_left();
             if left_trimmed.starts_with(RUSTFMT_CUSTOM_COMMENT_PREFIX) {
-                left_trimmed.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX)
+                let orig = left_trimmed.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX);
+                // due to comment wrapping, a line that was originaly behind `#` is split over
+                // multiple lines, which needs then to be prefixed with a `#`
+                if !orig.trim_left().starts_with("# ") {
+                    format!("# {}", orig)
+                } else {
+                    orig.to_string()
+                }
             } else {
-                line
+                line.to_string()
             }
         })
         .collect::<Vec<_>>()
diff --git a/tests/source/wrapped_hidden_code_block.rs b/tests/source/wrapped_hidden_code_block.rs
new file mode 100644 (file)
index 0000000..d8de844
--- /dev/null
@@ -0,0 +1,10 @@
+// rustfmt-max_width: 79
+// rustfmt-wrap_comments: true
+
+/// ```rust
+/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd)not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
+///
+/// // Est lectus hendrerit lorem, eget dignissim orci nisl sit amet massa. Etiam volutpat lobortis eros.
+/// let x = 42;
+/// ```
+fn func() {}
diff --git a/tests/target/wrapped_hidden_code_block.rs b/tests/target/wrapped_hidden_code_block.rs
new file mode 100644 (file)
index 0000000..572f448
--- /dev/null
@@ -0,0 +1,13 @@
+// rustfmt-max_width: 79
+// rustfmt-wrap_comments: true
+
+/// ```rust
+/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature,
+/// # stdsimd)not(dox), feature(cfg_target_feature, target_feature,
+/// # stdsimd))]
+///
+/// // Est lectus hendrerit lorem, eget dignissim orci nisl sit amet massa.
+/// // Etiam volutpat lobortis eros.
+/// let x = 42;
+/// ```
+fn func() {}