@@ -26,6 +26,7 @@ use std::ops::Range;
2626use url:: Url ;
2727
2828mod doc_comment_double_space_linebreaks;
29+ mod doc_suspicious_footnotes;
2930mod include_in_doc_without_cfg;
3031mod lazy_continuation;
3132mod link_with_quotes;
@@ -608,6 +609,34 @@ declare_clippy_lint! {
608609 "double-space used for doc comment linebreak instead of `\\ `"
609610}
610611
612+ declare_clippy_lint ! {
613+ /// ### What it does
614+ /// Detects syntax that looks like a footnote reference,
615+ /// because it matches the regexp `\[\^[0-9]+\]`,
616+ /// but has no referent.
617+ ///
618+ /// ### Why is this bad?
619+ /// This probably means that a definition was meant to exist,
620+ /// but was not written.
621+ ///
622+ /// ### Example
623+ /// ```no_run
624+ /// /// This is not a footnote[^1], because no definition exists.
625+ /// fn my_fn() {}
626+ /// ```
627+ /// Use instead:
628+ /// ```no_run
629+ /// /// This is a footnote[^1].
630+ /// ///
631+ /// /// [^1]: defined here
632+ /// fn my_fn() {}
633+ /// ```
634+ #[ clippy:: version = "1.88.0" ]
635+ pub DOC_SUSPICIOUS_FOOTNOTES ,
636+ suspicious,
637+ "looks like a link or footnote ref, but with no definition"
638+ }
639+
611640pub struct Documentation {
612641 valid_idents : FxHashSet < String > ,
613642 check_private_items : bool ,
@@ -639,7 +668,8 @@ impl_lint_pass!(Documentation => [
639668 DOC_OVERINDENTED_LIST_ITEMS ,
640669 TOO_LONG_FIRST_DOC_PARAGRAPH ,
641670 DOC_INCLUDE_WITHOUT_CFG ,
642- DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS
671+ DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS ,
672+ DOC_SUSPICIOUS_FOOTNOTES ,
643673] ) ;
644674
645675impl EarlyLintPass for Documentation {
@@ -1147,7 +1177,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
11471177 // Don't check the text associated with external URLs
11481178 continue ;
11491179 }
1150- text_to_check. push ( ( text, range, code_level) ) ;
1180+ text_to_check. push ( ( text, range. clone ( ) , code_level) ) ;
1181+ doc_suspicious_footnotes:: check ( cx, doc, range, & fragments) ;
11511182 }
11521183 }
11531184 FootnoteReference ( _) => { }
0 commit comments