@@ -33,6 +33,7 @@ use std::ops::Range;
3333use url:: Url ;
3434
3535mod empty_line_after;
36+ mod include_in_doc_without_cfg;
3637mod link_with_quotes;
3738mod markdown;
3839mod missing_headers;
@@ -532,6 +533,29 @@ declare_clippy_lint! {
532533 "empty line after doc comments"
533534}
534535
536+ declare_clippy_lint ! {
537+ /// ### What it does
538+ /// Checks if included files in doc comments are included only for `cfg(doc)`.
539+ ///
540+ /// ### Why is this bad?
541+ /// These files are not useful for compilation but will still be included.
542+ /// Also, if any of these non-source code file is updated, it will trigger a
543+ /// recompilation.
544+ ///
545+ /// ### Example
546+ /// ```ignore
547+ /// #![doc = include_str!("some_file.md")]
548+ /// ```
549+ /// Use instead:
550+ /// ```no_run
551+ /// #![cfg_attr(doc, doc = include_str!("some_file.md"))]
552+ /// ```
553+ #[ clippy:: version = "1.84.0" ]
554+ pub DOC_INCLUDE_WITHOUT_CFG ,
555+ suspicious,
556+ "check if files included in documentation are behind `cfg(doc)`"
557+ }
558+
535559pub struct Documentation {
536560 valid_idents : FxHashSet < String > ,
537561 check_private_items : bool ,
@@ -690,6 +714,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
690714 Some ( ( "fake" . into ( ) , "fake" . into ( ) ) )
691715 }
692716
717+ include_in_doc_without_cfg:: check ( cx, attrs) ;
693718 if suspicious_doc_comments:: check ( cx, attrs) || empty_line_after:: check ( cx, attrs) || is_doc_hidden ( attrs) {
694719 return None ;
695720 }
0 commit comments