Skip to content

Commit

Permalink
Rollup merge of #88735 - hnj2:patch-1, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JohnTitor authored Sep 17, 2021
2 parents 0f06e36 + 5f464bb commit 758c7bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustdoc/passes/doc_test_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo

if cx.tcx.hir().attrs(hir_id).lists(sym::doc).has_word(sym::hidden)
|| inherits_doc_hidden(cx.tcx, hir_id)
|| cx.tcx.hir().span(hir_id).in_derive_expansion()
{
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc-ui/lint-missing-doc-code-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ impl Clone for Struct {
}



/// doc
///
/// ```
/// println!("hello");
/// ```
#[derive(Clone)]
pub struct NiceStruct;

#[doc(hidden)]
pub mod foo {
pub fn bar() {}
Expand Down

0 comments on commit 758c7bc

Please sign in to comment.