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

missing_docs_in_private_items: false negative when used with clap derive #13996

Open
stevenengler opened this issue Jan 13, 2025 · 0 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@stevenengler
Copy link
Contributor

stevenengler commented Jan 13, 2025

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
@stevenengler stevenengler added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

1 participant