@@ -26,6 +26,7 @@ use std::ops::Range;
26
26
use url:: Url ;
27
27
28
28
mod doc_comment_double_space_linebreaks;
29
+ mod doc_suspicious_footnotes;
29
30
mod include_in_doc_without_cfg;
30
31
mod lazy_continuation;
31
32
mod link_with_quotes;
@@ -608,6 +609,34 @@ declare_clippy_lint! {
608
609
"double-space used for doc comment linebreak instead of `\\ `"
609
610
}
610
611
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
+
611
640
pub struct Documentation {
612
641
valid_idents : FxHashSet < String > ,
613
642
check_private_items : bool ,
@@ -639,7 +668,8 @@ impl_lint_pass!(Documentation => [
639
668
DOC_OVERINDENTED_LIST_ITEMS ,
640
669
TOO_LONG_FIRST_DOC_PARAGRAPH ,
641
670
DOC_INCLUDE_WITHOUT_CFG ,
642
- DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS
671
+ DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS ,
672
+ DOC_SUSPICIOUS_FOOTNOTES ,
643
673
] ) ;
644
674
645
675
impl EarlyLintPass for Documentation {
@@ -1147,7 +1177,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
1147
1177
// Don't check the text associated with external URLs
1148
1178
continue ;
1149
1179
}
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) ;
1151
1182
}
1152
1183
}
1153
1184
FootnoteReference ( _) => { }
0 commit comments