]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for unnecessary calls to [`ToOwned::to_owned`](https://doc.rust-lang.org/std/borrow/trait.ToOwned.html#tymethod.to_owned)
3and other `to_owned`-like functions.
4
5### Why is this bad?
6The 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
10owned 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```
15let path = std::path::Path::new("x");
16foo(&path.to_string_lossy().to_string());
17fn foo(s: &str) {}
18```
19Use instead:
20```
21let path = std::path::Path::new("x");
22foo(&path.to_string_lossy());
23fn foo(s: &str) {}
24```