Skip to content

Unable to expect the missing_panics_doc and missing_errors_doc lints on main function #14491

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

Open
CardboardTurkey opened this issue Mar 28, 2025 · 4 comments · May be fixed by #14505
Open

Unable to expect the missing_panics_doc and missing_errors_doc lints on main function #14491

CardboardTurkey opened this issue Mar 28, 2025 · 4 comments · May be fixed by #14505
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@CardboardTurkey
Copy link

CardboardTurkey commented Mar 28, 2025

Summary

My code base denies clippy::missing_panics_doc, clippy::missing_errors_doc and clippy::allow_attributes globally. However I also have a pub main function that doesn't need documentation.

If I use expect to allow the first two on main, clippy complains that the lint is unfulfilled - even though it has stopped complaining about the missing docs.

Everything works fine on functions that aren't main.

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=acbdff6f05c01e67eee4ad557ff6e06a

Reproducer

I tried this code:

#![deny(clippy::missing_panics_doc)]
#![deny(clippy::missing_errors_doc)]
#![deny(clippy::allow_attributes)]

use std::env::var;

#[expect(clippy::missing_panics_doc, reason = "main doesn't need docs")]
#[expect(clippy::missing_errors_doc, reason = "main doesn't need docs")]
pub fn main() -> Result<(), &'static str> {
    let val = var("Hello").unwrap();
    match val.as_str() {
        "hello" => Ok(()),
        _ => Err("Oh no"),
    }
}

I expected to see this happen:

No complaints from clippy

Instead, this happened:

Clippy complains about unfulfilled lints

    Checking playground v0.0.1 (/playground)
warning: this lint expectation is unfulfilled
 --> src/main.rs:6:10
  |
6 | #[expect(clippy::missing_panics_doc, reason = "main doesn't need docs")]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: main doesn't need docs
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

warning: this lint expectation is unfulfilled
 --> src/main.rs:7:10
  |
7 | #[expect(clippy::missing_errors_doc, reason = "main doesn't need docs")]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: main doesn't need docs

warning: `playground` (bin "playground") generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s

Version

rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7

Additional Labels

No response

@CardboardTurkey CardboardTurkey added the C-bug Category: Clippy is not doing the correct thing label Mar 28, 2025
@CardboardTurkey CardboardTurkey changed the title Unable to expect the missing_panics_doc and missing_errors_doc on main function Unable to expect the missing_panics_doc and missing_errors_doc lints on main function Mar 28, 2025
@longfangsong
Copy link

@rustbot claim

@longfangsong
Copy link

longfangsong commented Mar 30, 2025

In fact clippy::missing_panics_doc and clippy::missing_errors_doc are not checked on main.

I'm not very sure whether it is something by design (the document does not clarify this) but I opened #14505 anyway. Let's see how the maitainers think about this.

@CardboardTurkey
Copy link
Author

@longfangsong Ah you made me realise something. If I remove the expects from the playground example, you're right - clippy doesn't complain about lack of docs on main.

However in my actual codebase I'm not using a main.rs file, but instead a file in src/bin. There it does complain about the lack of docs on main.

@Alexendoo
Copy link
Member

Are you including the src/bin file in another context - e.g. if the lint is triggering in src/bin/foo.rs are you making foo a module of the library target or another bin target?

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants