rust-lang / rust-lang/rust-clippy

A lint should prevent the use of `assert!()`

Open
#16,346 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

The changes suggested by manual_assert (that is, switching to assert!) cause the code that panics to no longer trigger the panic lint.

Lint Name

panic

Reproducer

I tried this code:

#[expect(clippy::panic, reason = "allowed")]
#[expect(clippy::assertions_on_constants, reason = "simple repro")]
fn main() {
    assert!(false, "oh no")
}

(playground)

I expected it to compile with no warnings.

Instead, this happened:

warning: this lint expectation is unfulfilled
 --> src/main.rs:1:10
  |
1 | #[expect(clippy::panic, reason = "allowed")]
  |          ^^^^^^^^^^^^^
  |
  = note: allowed
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

In comparison, the following matches the panic lint but also the manual_assert lint:

#[expect(clippy::panic, reason = "allowed")]
fn main() {
    if true {
        panic!("oh no");
    }
}

(playground)

Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3

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.

Research direction

Start by running the reproducer from the issue and comparing it with the panic! example. Trace how the manual_assert and panic lints handle these forms; done means the intended assert! case is covered without breaking the existing lint behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.