redundant_pattern_matching
: if let Err(_) = ... else
and if ....is_err()
are not the same
#14113
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
The clippy lint is suggesting to replace
if let pattern = blurp else
withif blurp.is_err()
, which are not synonymous. The problem with the drop order is already warned about; however there's another point that is specific tolet ... else
:let ... else
forces you to handle theelse
-case by diverging, whereas a normalif
-clause does not. Bugs likegoto fail
(different language, same underlying problem) show that this is a problem in practice.let ... else
has different, significantly stronger semantics regarding error handling and bug resilience; and clippy's suggestion to just goif
is unfortunate in my opinion.If people use
let ... else
, it is not unlikely that they use it intentionally to get those stronger semantics, and I personally consider this warning (and the suggested replacement) a false-positive forlet ... else
-cases (at least on the default warning level).Lint Name
redundant_pattern_matching
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: