diff options
| author | bors <bors@rust-lang.org> | 2021-12-15 10:46:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-12-15 10:46:43 +0000 |
| commit | 40fd785199d80a06c1a1664d64209f78343c0e05 (patch) | |
| tree | fa0c4f45b7d51dc4d4d3b158e78fbcc59d9c56eb /compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs | |
| parent | aa3648af504389ece9c5e09b848b450edad3ac38 (diff) | |
| parent | b8913894a13431bea99400dc9f53a1fd9f41a6c6 (diff) | |
| download | rust-40fd785199d80a06c1a1664d64209f78343c0e05.tar.gz rust-40fd785199d80a06c1a1664d64209f78343c0e05.zip | |
Auto merge of #7978 - smoelius:master, r=llogiq
Add `unnecessary_to_owned` lint
This PR adds a lint to check for unnecessary calls to `ToOwned::to_owned` and other similar functions (e.g., `Cow::into_owned`, `ToString::to_string`, etc.).
The lint checks for expressions of the form `&receiver.to_owned_like()` used in a position requiring type `&T` where one of the following is true:
* `receiver`'s type is `T` exactly
* `receiver`'s type implements `Deref<Target = T>`
* `receiver`'s type implements `AsRef<T>`
The lint additionally checks for expressions of the form `receiver.to_owned_like()` used as arguments of type `impl AsRef<T>`.
It would be nice if the lint could also check for expressions used as arguments to functions like the following:
```
fn foo<T: AsRef<str>>(x: T) { ... }
```
However, I couldn't figure out how to determine whether a function input type was instantiated from a parameter with a trait bound.
If someone could offer me some guidance, I would be happy to add such functionality.
Closes #7933
changelog: Add [`unnecessary_to_owned`] lint
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs')
0 files changed, 0 insertions, 0 deletions
