Closed
Description
What it does
With bool::then_some
stabilized in Rust 1.62, uses of bool::then
with a closure consisting of a simple body without side effects should become bool::then_some
.
This should be part of the existing unnecessary_lazy_evaluations
.
Lint Name
unnecessary_lazy_evaluations
Category
style
Advantage
No response
Drawbacks
No response
Example
fn f(cond: bool) -> Option<u64> {
cond.then(|| 42)
}
Could be written as:
fn f(cond: bool) -> Option<u64> {
cond.then_some(42)
}