suggest filter
, map
instead of if let Some(..) { Some() } else { None }
on Options?
#10078
Labels
A-lint
Area: New lints
What it does
I was looking at some rustc code and noticed some
if let Some(..)
code where we would map back toSome(x)
orNone
in the end and wondered if it would make sense to usefilter
andmap
here insteadLint Name
not sure
Category
pedantic
Advantage
Code is shorter but I am not sure if its easier to understand
Drawbacks
Not sure if readability is actually improved.
Example
Could be written as:
(we have an
Option
here so we canfilter
toNone
instead ofif let .. else { None }
and we canmap(|x| i)
instead ofif let .. { Some(i) }
)I think the second example looks a bit more streamlined and might be easier to understand it doesn't have all the if let else control flow, on the other hand, the explicit control flow might make the code better to understand as well (explicit is better than implicit etc..)
The text was updated successfully, but these errors were encountered: