clippy suggests map.entry().or_insert() when it shouldn't #1450
Labels
C-bug
Category: Clippy is not doing the correct thing
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
I-false-positive
Issue: The lint was triggered on code it shouldn't have
In the above, clippy suggests
map.entry(v).or_insert(expensive_can_fail(v)?)
, but that calls the expensive function even if it is not needed.Normally you could use
map.entry(v).or_insert_with(/*...*/)
to call the function only when needed, but in this case, sinceexpensive_can_fail(v)?
can return, that doesn't work either. Maybe in this case clippy can suggestwhich avoids calling the expensive function needlessly and avoids the double key search.
The text was updated successfully, but these errors were encountered: