| 
 | 1 | +#![allow(clippy::lint_without_lint_pass)]  | 
 | 2 | + | 
1 | 3 | mod lazy_continuation;  | 
2 | 4 | mod too_long_first_doc_paragraph;  | 
3 | 5 | 
 
  | 
@@ -33,6 +35,7 @@ use std::ops::Range;  | 
33 | 35 | use url::Url;  | 
34 | 36 | 
 
  | 
35 | 37 | mod empty_line_after;  | 
 | 38 | +mod include_in_doc_without_cfg;  | 
36 | 39 | mod link_with_quotes;  | 
37 | 40 | mod markdown;  | 
38 | 41 | mod missing_headers;  | 
@@ -532,6 +535,29 @@ declare_clippy_lint! {  | 
532 | 535 |     "empty line after doc comments"  | 
533 | 536 | }  | 
534 | 537 | 
 
  | 
 | 538 | +declare_clippy_lint! {  | 
 | 539 | +    /// ### What it does  | 
 | 540 | +    /// Checks if included files in doc comments are included only for `cfg(doc)`.  | 
 | 541 | +    ///  | 
 | 542 | +    /// ### Why is this bad?  | 
 | 543 | +    /// These files are not useful for compilation but will still be included.  | 
 | 544 | +    /// Also, if any of these non-source code file is updated, it will trigger a  | 
 | 545 | +    /// recompilation.  | 
 | 546 | +    ///  | 
 | 547 | +    /// ### Example  | 
 | 548 | +    /// ```ignore  | 
 | 549 | +    /// #![doc = include_str!("some_file.md")]  | 
 | 550 | +    /// ```  | 
 | 551 | +    /// Use instead:  | 
 | 552 | +    /// ```no_run  | 
 | 553 | +    /// #![cfg_attr(doc, doc = include_str!("some_file.md"))]  | 
 | 554 | +    /// ```  | 
 | 555 | +    #[clippy::version = "1.84.0"]  | 
 | 556 | +    pub DOC_INCLUDE_WITHOUT_CFG,  | 
 | 557 | +    pedantic,  | 
 | 558 | +    "check if files included in documentation are behind `cfg(doc)`"  | 
 | 559 | +}  | 
 | 560 | + | 
535 | 561 | pub struct Documentation {  | 
536 | 562 |     valid_idents: FxHashSet<String>,  | 
537 | 563 |     check_private_items: bool,  | 
@@ -561,6 +587,7 @@ impl_lint_pass!(Documentation => [  | 
561 | 587 |     EMPTY_LINE_AFTER_OUTER_ATTR,  | 
562 | 588 |     EMPTY_LINE_AFTER_DOC_COMMENTS,  | 
563 | 589 |     TOO_LONG_FIRST_DOC_PARAGRAPH,  | 
 | 590 | +    DOC_INCLUDE_WITHOUT_CFG,  | 
564 | 591 | ]);  | 
565 | 592 | 
 
  | 
566 | 593 | impl<'tcx> LateLintPass<'tcx> for Documentation {  | 
@@ -690,6 +717,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[  | 
690 | 717 |         Some(("fake".into(), "fake".into()))  | 
691 | 718 |     }  | 
692 | 719 | 
 
  | 
 | 720 | +    include_in_doc_without_cfg::check(cx, attrs);  | 
693 | 721 |     if suspicious_doc_comments::check(cx, attrs) || empty_line_after::check(cx, attrs) || is_doc_hidden(attrs) {  | 
694 | 722 |         return None;  | 
695 | 723 |     }  | 
 | 
0 commit comments