unnecessary_unwrap: should not trigger if the is_some
is just part of the conditional
#4530
Labels
C-enhancement
Category: Enhancement of lints, like adding more cases or adding help messages
L-suggestion
Lint: Improving, adding or fixing lint suggestions
unnecessary_unwrap
recommends thatfoo.is_some()
in a conditional followed byfoo.unwrap()
should be replaced by anif let
. That is usually good advice, however, if theis_some
is just part of the conditional, then the only way to useif let
is with nestedif
s.E.g.,
can only be rewritten as
which is not much of an improvement (and arguably no improvement at all). (In this case, using
match
might be better, but in some more complex examples it is not possible).I would much prefer is
unnecessary_unwrap
only triggered when it was possible to rewrite exactly using a singleif let
ormatch
.The text was updated successfully, but these errors were encountered: