RS.CLIPPY.MANUAL_NON_EXHAUSTIVE
Manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_non_exhaustive. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for manual implementations of the non-exhaustive pattern.
Why is this bad?
Using the #[non_exhaustive] attribute expresses better the intent and allows possible optimizations when applied to enums.
Example
struct S {
pub a: i32,
pub b: i32,
_c: (),
}
enum E {
A,
B,
#[doc(hidden)]
_C,
}
struct T(pub i32, pub i32, ());
Use instead:
#[non_exhaustive]
struct S {
pub a: i32,
pub b: i32,
}
#[non_exhaustive]
enum E {
A,
B,
}
#[non_exhaustive]
struct T(pub i32, pub i32);
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)