unnecessary_to_owned
suggestion changes maybe-cloning to always-cloning
#12806
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
When iterating over the contents of a
Cow<'a, [T]>
by value,clippy::unnecessary_to_owned
confidently proposes a change which will cause unnecessary element cloning in the case where theCow
isCow::Owned
. This isn't necessarily worse, but it isn't strictly better and shouldn't be recommended without qualification.Lint Name
unnecessary_to_owned
Reproducer
I tried this code:
I saw this happen:
Both versions of the code have flaws, but neither one is strictly superior to the other, and
case1
is likely better, so Clippy should not confidently recommend one.case1
, when givenBorrowed
, will unnecessarily create aVec
(rather than only cloning the elements).case2
, when givenOwned
, will unnecessarily clone all the elements (rather than moving them).Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: