Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustdoc shouldn't lint about missing code examples in derived traits #81775

Closed
toku-sa-n opened this issue Feb 5, 2021 · 3 comments · Fixed by #88735
Closed

Rustdoc shouldn't lint about missing code examples in derived traits #81775

toku-sa-n opened this issue Feb 5, 2021 · 3 comments · Fixed by #88735
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@toku-sa-n
Copy link

I tried this code:

#[deny(missing_doc_code_examples)]
/// Foo struct.
///
/// # Examples
///
/// ```
/// let f = Foo;
/// ```
#[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Foo;

I expected to see this happen: cargo doc succeeds.

Instead, this happened:

 Documenting foo v0.1.0 (/tmp/tmp.uwQktSx1yP/foo)
error: missing code example in this documentation
 --> src/lib.rs:9:16
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                ^^^^^
  |
note: the lint level is defined here
 --> src/lib.rs:1:8
  |
1 | #[deny(missing_doc_code_examples)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:16
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                ^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:10
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |          ^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:30
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                              ^^^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:56
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                                                        ^^

error: missing code example in this documentation
 --> src/lib.rs:9:39
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                                       ^^^

error: missing code example in this documentation
 --> src/lib.rs:9:60
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                                                            ^^^^^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:44
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                                            ^^^^^^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:23
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                       ^^^^^

error: missing code example in this documentation
 --> src/lib.rs:9:71
  |
9 | #[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
  |                                                                       ^^^^

error: aborting due to 10 previous errors

error: could not document `foo`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type lib --crate-name foo src/lib.rs -o /tmp/tmp.uwQktSx1yP/foo/target/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/tmp/tmp.uwQktSx1yP/foo/target/debug/deps --crate-version 0.1.0` (exit code: 1)

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

@toku-sa-n toku-sa-n added the C-bug Category: This is a bug. label Feb 5, 2021
@hellow554
Copy link
Contributor

searched nightlies: from nightly-2020-09-30 to nightly-2020-11-30
regressed nightly: nightly-2020-11-12
searched commits: from cf9cf7c to 5404efc
regressed commit: 38030ff

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc 2020-09-30 --end=2020-11-30 --script=./test.sh --access=github

so probably #78908?

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 5, 2021
@poliorcetics
Copy link
Contributor

What is the correct option here ? Ignoring derived traits or putting default examples on the derive for those types ?

The first seems hard to do but I'm maybe missing knowledge to see it done.

The second means the examples won't be very relevant to the type on which they are derived. For Clone this is not much of a problem, but for thing like serve::Serialize I can see it confusing people.

@jyn514
Copy link
Member

jyn514 commented Feb 5, 2021

I think rustdoc shouldn't require examples for derived traits.

let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local());
let (level, source) =
cx.tcx.lint_level_at_node(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id);
level != lint::Level::Allow || matches!(source, LintLevelSource::Default)

A possible fix is to only call source_callsite() in render, and use the macro span everywhere else for the purpose of lints.

@jyn514 jyn514 changed the title Derivable stdlib traits don't have code examples Rustdoc shouldn't lint about missing code examples in derived traits Apr 22, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Sep 17, 2021
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 rust-lang#81775
@bors bors closed this as completed in 5f464bb Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants