Skip to content

missing_docs_in_private_items: false negative when used with clap derive #13996

Open
@stevenengler

Description

@stevenengler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions