]>
Commit | Line | Data |
---|---|---|
f2b60f7d FG |
1 | ### What it does |
2 | Checks for unnecessary calls to [`ToOwned::to_owned`](https://doc.rust-lang.org/std/borrow/trait.ToOwned.html#tymethod.to_owned) | |
3 | and other `to_owned`-like functions. | |
4 | ||
5 | ### Why is this bad? | |
6 | The unnecessary calls result in useless allocations. | |
7 | ||
8 | ### Known problems | |
9 | `unnecessary_to_owned` can falsely trigger if `IntoIterator::into_iter` is applied to an | |
10 | owned copy of a resource and the resource is later used mutably. See | |
11 | [#8148](https://github.com/rust-lang/rust-clippy/issues/8148). | |
12 | ||
13 | ### Example | |
14 | ``` | |
15 | let path = std::path::Path::new("x"); | |
16 | foo(&path.to_string_lossy().to_string()); | |
17 | fn foo(s: &str) {} | |
18 | ``` | |
19 | Use instead: | |
20 | ``` | |
21 | let path = std::path::Path::new("x"); | |
22 | foo(&path.to_string_lossy()); | |
23 | fn foo(s: &str) {} | |
24 | ``` |