bool::then
-> bool::then_some
within unnecessary_lazy_eval
can suggest fixes that can panic
#9814
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
bool::then
->bool::then_some
suggestions forunnecessary_lazy_eval
can be problematic if the underlying body of the closure is not actually trivial. See repro below for a concrete example.This is especially problematic because
cargo clippy --fix
will auto-fix this, which can inadvertently cause a new panic.Lint Name
unnecessary_lazy_eval
Reproducer
I tried this code:
I saw this happen:
This is incorrect, since
bool:then
will panic in a case wherethen_some
would not have.I expected to see this happen:
No clippy warning suggested.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: