Skip to content

Commit 758c7bc

Browse files
authored
Rollup merge of #88735 - hnj2:patch-1, r=GuillaumeGomez
Don't lint about missing code examples in derived traits When the `missing_doc_code_examples` lint is performed it also requires that derived Trait implementations have a code example for each member etc., which causes undesirable behavior. # Examples With `missing_doc_code_examples` enable we are not able to use the `Clone` derive macro due to the generated code not being documented: ```rust #[deny(rustdoc::missing_doc_code_examples)] /// docs /// ``` /// let s = SomeStruct; /// ``` #[derive(Clone)] pub struct SomeStruct; ``` yields: ``` Documenting testt v0.1.0 (<redacted>) error: missing code example in this documentation --> src/lib.rs:7:10 | 7 | #[derive(Clone)] | ^^^^^ | note: the lint level is defined here --> src/lib.rs:1:8 | 1 | #[deny(rustdoc::missing_doc_code_examples)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> src/lib.rs:7:10 | 7 | #[derive(Clone)] | ^^^^^ error: could not document `testt` Caused by: process didn't exit successfully: `rustdoc ... ``` closes #81775
2 parents 0f06e36 + 5f464bb commit 758c7bc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustdoc/passes/doc_test_lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
9696

9797
if cx.tcx.hir().attrs(hir_id).lists(sym::doc).has_word(sym::hidden)
9898
|| inherits_doc_hidden(cx.tcx, hir_id)
99+
|| cx.tcx.hir().span(hir_id).in_derive_expansion()
99100
{
100101
return false;
101102
}

src/test/rustdoc-ui/lint-missing-doc-code-example.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ impl Clone for Struct {
7878
}
7979

8080

81+
82+
/// doc
83+
///
84+
/// ```
85+
/// println!("hello");
86+
/// ```
87+
#[derive(Clone)]
88+
pub struct NiceStruct;
89+
8190
#[doc(hidden)]
8291
pub mod foo {
8392
pub fn bar() {}

0 commit comments

Comments
 (0)