-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
Description
unnecessary_unwrap
recommends that foo.is_some()
in a conditional followed by foo.unwrap()
should be replaced by an if let
. That is usually good advice, however, if the is_some
is just part of the conditional, then the only way to use if let
is with nested if
s.
E.g.,
if some_condition && foo.is_some() {
let foo = foo.unwrap();
...
}
can only be rewritten as
if some_condition {
if let Some(foo) = foo {
...
}
}
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 single if let
or match
.
behnam, enfipy, t-rapp, thomastay, booleancoercion and 2 more
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions