Closed
Description
What it does
The lint would detect cases where the new Option function is_some_and would be appropriate. Examples would be places where map()
converts an Option<T>
into an Option<bool>
and then unwrap_or(false)
is used. The library function is still experimental, but once it's stable, this would be a useful modernization suggestion.
Lint Name
option_is_some_with
Category
complexity
Advantage
Reduces function calls (even if they would optimize down), increases clarity.
Drawbacks
Low priority, since the existing approaches are functional, if less idiomatic/aesthetic.
Example
let x: Option<int> = Some(7);
x.map(|val| val > 5).unwrap_or(false)
Could be written as:
let x: Option<int> = Some(7);
x.is_some_and(|val| val > 5)