about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-12-15 10:46:43 +0000
committerbors <bors@rust-lang.org>2021-12-15 10:46:43 +0000
commit40fd785199d80a06c1a1664d64209f78343c0e05 (patch)
treefa0c4f45b7d51dc4d4d3b158e78fbcc59d9c56eb /compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
parentaa3648af504389ece9c5e09b848b450edad3ac38 (diff)
parentb8913894a13431bea99400dc9f53a1fd9f41a6c6 (diff)
downloadrust-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