Note serde-rs/json#405.
We could also lint to_vec on Cow<[T]> and probably others.
Note that this only applies when the Cow being inspected is owned by the caller. E.g. this lint would suggest code that doesn't compile when the caller has a &Cow. This shouldn't happen too often anyway, because the whole point of a Cow is that the user doesn't need to keep in his/her head whether it's a reference or an owned value. Actually, while we're here, may I also suggest a lint against passing Cow by reference?
See additional discussions in the duplicate issue https://github.com/rust-lang/rust-clippy/issues/5987
Note that the claim that String: From<Cow<'_, str>> allocates is no longer true
@Kixunil it is not String: From<Cow<str>> that is of concern here; instead, it is only Cow: ToString which has no choice but to allocate.
Ah, I misread that code in the serde issue.
Basically, this is a specific case of the more general "did you mean to move instead of clone this" set of errors.
Most helpful comment
Basically, this is a specific case of the more general "did you mean to move instead of clone this" set of errors.