obfuscated_if_else
doesn't check for side effects in subexpressions
#14034
Labels
C-bug
Category: Clippy is not doing the correct thing
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
The lint suggests changing
b.then_some(x).unwrap_or(y)
intoif b { x } else { y }
without checking that the evaluation ofx
andy
(whose evaluation is short-circuited in the suggested change) doesn't have any side effect.Reproducer
I tried this code:
which runs without error.
Clippy proposed to transform it into:
which fails the test
assert_eq!(c, 2)
because only one call toallocate
now took place.At minimum, the applicability should be downgraded from
MachineApplicable
toMaybeIncorrect
.Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: