Skip to content

Suggest into_owned instead of to_string for Cow<str> #2387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
clarfonthey opened this issue Jan 21, 2018 · 6 comments
Open

Suggest into_owned instead of to_string for Cow<str> #2387

clarfonthey opened this issue Jan 21, 2018 · 6 comments
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@clarfonthey
Copy link

Note serde-rs/json#405.

We could also lint to_vec on Cow<[T]> and probably others.

@H2CO3
Copy link

H2CO3 commented Jan 27, 2018

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?

@oli-obk oli-obk added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Feb 5, 2018
@Veetaha
Copy link

Veetaha commented Dec 7, 2020

See additional discussions in the duplicate issue #5987

@Kixunil
Copy link

Kixunil commented Dec 7, 2020

Note that the claim that String: From<Cow<'_, str>> allocates is no longer true

@H2CO3
Copy link

H2CO3 commented Dec 7, 2020

@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.

@Kixunil
Copy link

Kixunil commented Dec 7, 2020

Ah, I misread that code in the serde issue.

@clarfonthey
Copy link
Author

Basically, this is a specific case of the more general "did you mean to move instead of clone this" set of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

5 participants