RS.CLIPPY.SHOULD_PANIC_WITHOUT_EXPECT

Ensures that all `should_panic` attributes specify its expected panic message

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: should_panic_without_expect. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for #[should_panic] attributes without specifying the expected panic message.

Why is this bad?

The expected panic message should be specified to ensure that the test is actually panicking with the expected message, and not another unrelated panic.

Example

fn random() -> i32 { 0 }

#[should_panic]
#[test]
fn my_test() {
    let _ = 1 / random();
}

Use instead:

fn random() -> i32 { 0 }

#[should_panic = "attempt to divide by zero"]
#[test]
fn my_test() {
    let _ = 1 / random();
}