rust-lang / rust-lang/rust-clippy

Unable to `expect` the `missing_panics_doc` and `missing_errors_doc` lints on main function

Open
#14,491 4 comments 0 reactions 1 assignee View on GitHub

@longfangsong is already working on this.

Since Mar 29, 2025.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.