about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--clippy_lints/src/declared_lints.rs2
-rw-r--r--clippy_lints/src/doc/doc_comment_double_space_linebreak.rs37
-rw-r--r--clippy_lints/src/doc/mod.rs2
-rw-r--r--tests/ui/doc/doc_comment_double_space_linebreak.stderr89
5 files changed, 49 insertions, 83 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91608fb8d1e..94550f531ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5570,8 +5570,8 @@ Released 2018-09-13
 [`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
 [`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
 [`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
-[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
 [`doc_comment_double_space_linebreak`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_comment_double_space_linebreak
+[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
 [`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
 [`doc_link_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_code
 [`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs
index 586ee22d9ef..a99c9ce4635 100644
--- a/clippy_lints/src/declared_lints.rs
+++ b/clippy_lints/src/declared_lints.rs
@@ -137,8 +137,8 @@ pub static LINTS: &[&crate::LintInfo] = &[
     crate::disallowed_names::DISALLOWED_NAMES_INFO,
     crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO,
     crate::disallowed_types::DISALLOWED_TYPES_INFO,
-    crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
     crate::doc::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK_INFO,
+    crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
     crate::doc::DOC_LAZY_CONTINUATION_INFO,
     crate::doc::DOC_LINK_CODE_INFO,
     crate::doc::DOC_LINK_WITH_QUOTES_INFO,
diff --git a/clippy_lints/src/doc/doc_comment_double_space_linebreak.rs b/clippy_lints/src/doc/doc_comment_double_space_linebreak.rs
index 4c2475ad8d8..c50a987101a 100644
--- a/clippy_lints/src/doc/doc_comment_double_space_linebreak.rs
+++ b/clippy_lints/src/doc/doc_comment_double_space_linebreak.rs
@@ -1,41 +1,20 @@
-use clippy_utils::diagnostics::span_lint_and_then;
-use clippy_utils::source::snippet_opt;
+use clippy_utils::diagnostics::span_lint_and_sugg;
 use rustc_errors::Applicability;
 use rustc_lint::LateContext;
-use rustc_span::Span;
+use rustc_span::{BytePos, Span};
 
 use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
 
 pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
-    let replacements: Vec<_> = collect_doc_replacements(cx, collected_breaks);
-
-    if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
-        span_lint_and_then(
+    for r_span in collected_breaks {
+        span_lint_and_sugg(
             cx,
             DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
-            lo_span.to(hi_span),
+            r_span.with_hi(r_span.lo() + BytePos(2)),
             "doc comment uses two spaces for a hard line break",
-            |diag| {
-                diag.multipart_suggestion(
-                    "replace this double space with a backslash",
-                    replacements,
-                    Applicability::MachineApplicable,
-                );
-            },
+            "replace this double space with a backslash",
+            "\\".to_owned(),
+            Applicability::MachineApplicable,
         );
     }
 }
-
-fn collect_doc_replacements(cx: &LateContext<'_>, spans: &[Span]) -> Vec<(Span, String)> {
-    spans
-        .iter()
-        .map(|span| {
-            // we already made sure the snippet exists when collecting spans
-            let s = snippet_opt(cx, *span).expect("snippet was already validated to exist");
-            let after_newline = s.trim_start_matches(' ');
-
-            let new_comment = format!("\\{after_newline}");
-            (*span, new_comment)
-        })
-        .collect()
-}
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs
index d36ef10f4b9..1317bbb4727 100644
--- a/clippy_lints/src/doc/mod.rs
+++ b/clippy_lints/src/doc/mod.rs
@@ -772,8 +772,6 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
         return None;
     }
 
-    suspicious_doc_comments::check(cx, attrs);
-
     let (fragments, _) = attrs_to_doc_fragments(
         attrs.iter().filter_map(|attr| {
             if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
diff --git a/tests/ui/doc/doc_comment_double_space_linebreak.stderr b/tests/ui/doc/doc_comment_double_space_linebreak.stderr
index 4c77f8e1503..dccec5b8c85 100644
--- a/tests/ui/doc/doc_comment_double_space_linebreak.stderr
+++ b/tests/ui/doc/doc_comment_double_space_linebreak.stderr
@@ -1,76 +1,65 @@
 error: doc comment uses two spaces for a hard line break
   --> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
    |
-LL |   //! Should warn on double space linebreaks  
-   |  ___________________________________________^
-LL | | //! in file/module doc comment
-   | |____^
+LL | //! Should warn on double space linebreaks  
+   |                                           ^^ help: replace this double space with a backslash: `\`
    |
    = note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`
-help: replace this double space with a backslash
-   |
-LL ~ //! Should warn on double space linebreaks\
-LL ~ //! in file/module doc comment
-   |
 
 error: doc comment uses two spaces for a hard line break
   --> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
    |
-LL |   /// Should warn when doc comment uses double space  
-   |  ___________________________________________________^
-LL | | /// as a line-break, even when there are multiple  
-LL | | /// in a row
-   | |____^
-   |
-help: replace this double space with a backslash
-   |
-LL ~ /// Should warn when doc comment uses double space\
-LL ~ /// as a line-break, even when there are multiple\
-LL ~ /// in a row
+LL | /// Should warn when doc comment uses double space  
+   |                                                   ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:36:50
    |
+LL | /// as a line-break, even when there are multiple  
+   |                                                  ^^ help: replace this double space with a backslash: `\`
 
 error: doc comment uses two spaces for a hard line break
   --> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
    |
-LL |   /// 🌹 are 🟥  
-   |  ______________^
-LL | | /// 🌷 are 🟦  
-LL | | /// 📎 is 😎  
-LL | | /// and so are 🫵  
-LL | | /// (hopefully no formatting weirdness linting this)
-   | |____^
+LL | /// 🌹 are 🟥  
+   |              ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:45:12
    |
-help: replace this double space with a backslash
+LL | /// 🌷 are 🟦  
+   |              ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:46:11
    |
-LL ~ /// 🌹 are 🟥\
-LL ~ /// 🌷 are 🟦\
-LL ~ /// 📎 is 😎\
-LL ~ /// and so are 🫵\
-LL ~ /// (hopefully no formatting weirdness linting this)
+LL | /// 📎 is 😎  
+   |             ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:47:17
    |
+LL | /// and so are 🫵  
+   |                  ^^ help: replace this double space with a backslash: `\`
 
 error: doc comment uses two spaces for a hard line break
   --> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
    |
-LL |   /// here we mix  
-   |  ________________^
-LL | | /// double spaces\
-LL | | /// and also  
-LL | | /// adding backslash\
-LL | | /// to some of them  
-LL | | /// to see how that looks
-   | |____^
-   |
-help: replace this double space with a backslash
+LL | /// here we mix  
+   |                ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:88:13
    |
-LL ~ /// here we mix\
-LL ~ /// double spaces\
-LL ~ /// and also\
-LL ~ /// adding backslash\
-LL ~ /// to some of them\
-LL ~ /// to see how that looks
+LL | /// and also  
+   |             ^^ help: replace this double space with a backslash: `\`
+
+error: doc comment uses two spaces for a hard line break
+  --> tests/ui/doc/doc_comment_double_space_linebreak.rs:90:20
    |
+LL | /// to some of them  
+   |                    ^^ help: replace this double space with a backslash: `\`
 
-error: aborting due to 4 previous errors
+error: aborting due to 10 previous errors