RS.CLIPPY.IF_THEN_SOME_ELSE_NONE
Finds if-else that could be written using either `bool::then` or `bool::then_some`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: if_then_some_else_none. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for if-else that could be written using either bool::then or bool::then_some.
Why restrict this?
Looks a little redundant. Using bool::then is more concise and incurs no loss of clarity.
For simple calculations and known values, use bool::then_some, which is eagerly evaluated
in comparison to bool::then.
Example
let a = if v.is_empty() {
println!("true!");
Some(42)
} else {
None
};
Could be written:
let a = v.is_empty().then(|| {
println!("true!");
42
});
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)