rust-lang / rust-lang/rust-clippy
`missing_docs_in_private_items`: false negative when used with clap derive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I don't really understand this bug, so sorry about the bad title. If someone figures out why it's not working, feel free to add a better title. I'm also not sure how to minimize the example any further.
The private function foo without doc comments immediately after the Cli struct doesn't trigger the missing_docs_in_private_items lint. If you remove the args from Cli, then the lint does correctly trigger on foo. It seems like the clap derive is breaking the lint in some way, but this seems like a bug in the lint rather than a bug in clap.
I've reproduced this on nightly and the latest stable 1.84. I've tried looking at the output of cargo rustc --profile=check -- -Zunpretty=expanded but nothing stands out to me.
Lint Name
missing_docs_in_private_items
Reproducer
I tried this code:
//! Foo
#![deny(clippy::missing_docs_in_private_items)]
use clap::{Args, Parser};
/// CliArgs
#[derive(Args)]
pub(crate) struct CliArgs {}
/// Cli
#[derive(Parser)]
pub(crate) struct Cli {
/// args
#[clap(flatten)]
pub(crate) args: CliArgs,
}
// !! this should require a doc comment due to 'missing_docs_in_private_items'
fn foo() {}
fn main() {
foo();
}
[dependencies]
clap = { version = "4.5.26", features = ["derive"] }
I expected to see this happen:
Checking clippy-test v0.1.0 (/tmp/clippy-test)
error: missing documentation for a function
--> src/main.rs:20:1
|
20 | fn foo() {}
| ^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
note: the lint level is defined here
--> src/main.rs:3:9
|
3 | #![deny(clippy::missing_docs_in_private_items)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: could not compile `clippy-test` (bin "clippy-test") due to 1 previous error
Instead, this happened:
Checking clippy-test v0.1.0 (/tmp/clippy-test)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Version
rustc 1.86.0-nightly (48a426eca 2025-01-12)
binary: rustc
commit-hash: 48a426eca9df23b24b3559e545cf88dee61d4de9
commit-date: 2025-01-12
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the src/main.rs reproducer and run the reported cargo check command to confirm the false negative. Trace the missing_docs_in_private_items lint from this case and verify that the completed fix produces the expected missing-documentation diagnostic for foo when Cli contains flattened args.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100