]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/src/docs/unnecessary_to_owned.txt
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / unnecessary_to_owned.txt
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 ```