@@ -28,6 +28,7 @@ use rustc_span::{sym, Span};
2828use std:: ops:: Range ;
2929use url:: Url ;
3030
31+ mod doc_comment_double_space_linebreak;
3132mod link_with_quotes;
3233mod markdown;
3334mod missing_headers;
@@ -420,6 +421,39 @@ declare_clippy_lint! {
420421 "require every line of a paragraph to be indented and marked"
421422}
422423
424+ declare_clippy_lint ! {
425+ /// ### What it does
426+ /// Detects doc comment linebreaks that use double spaces to separate lines, instead of back-slash (\).
427+ ///
428+ /// ### Why is this bad?
429+ /// Double spaces, when used as doc comment linebreaks, can be difficult to see, and may
430+ /// accidentally be removed during automatic fofmatting or manual refactoring. The use of a back-slash (\)
431+ /// is clearer in this regard.
432+ ///
433+ /// ### Example
434+ /// The two dots in this example represent a double space.
435+ /// ```no_run
436+ /// /// This command takes two numbers as inputs and..
437+ /// /// adds them together, and then returns the result.
438+ /// fn add(l: i32, r: i32) -> i32 {
439+ /// l + r
440+ /// }
441+ /// ``````
442+ ///
443+ /// Use instead:
444+ /// ```no_run
445+ /// /// This command takes two numbers as inputs and \
446+ /// /// adds them together, and then returns the result.
447+ /// fn add(l: i32, r: i32) -> i32 {
448+ /// l + r
449+ /// }
450+ /// ```
451+ #[ clippy:: version = "1.80.0" ]
452+ pub DOC_COMMENT_DOUBLE_SPACE_LINEBREAK ,
453+ restriction,
454+ "double-space used for doc comment linebreak instead of `\\ `"
455+ }
456+
423457#[ derive( Clone ) ]
424458pub struct Documentation {
425459 valid_idents : FxHashSet < String > ,
@@ -447,6 +481,7 @@ impl_lint_pass!(Documentation => [
447481 SUSPICIOUS_DOC_COMMENTS ,
448482 EMPTY_DOCS ,
449483 DOC_LAZY_CONTINUATION ,
484+ DOC_COMMENT_DOUBLE_SPACE_LINEBREAK
450485] ) ;
451486
452487impl < ' tcx > LateLintPass < ' tcx > for Documentation {
@@ -569,6 +604,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
569604 }
570605
571606 suspicious_doc_comments:: check ( cx, attrs) ;
607+ doc_comment_double_space_linebreak:: check ( cx, attrs) ;
572608
573609 let ( fragments, _) = attrs_to_doc_fragments (
574610 attrs. iter ( ) . filter_map ( |attr| {
0 commit comments