diff options
| author | Phil Hansch <dev@phansch.net> | 2019-10-04 08:08:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-04 08:08:58 +0200 |
| commit | 8d2912ec00a42698e44db924495bcc30a090ee2b (patch) | |
| tree | f5fd4950c2ae59975eff323e6191578a74564e12 /tests/ui/map_clone.fixed | |
| parent | b824f021d61ddee59695f20c7128c39d80e9e5b6 (diff) | |
| parent | 4cded6d9012bbfc77d13c7ef2a413402199a2a03 (diff) | |
| download | rust-8d2912ec00a42698e44db924495bcc30a090ee2b.tar.gz rust-8d2912ec00a42698e44db924495bcc30a090ee2b.zip | |
Rollup merge of #4509 - sinkuu:redundant_clone_fix, r=llogiq
Fix false-positive of redundant_clone and move to clippy::perf This PR introduces dataflow analysis to `redundant_clone` lint to filter out borrowed variables, which had been incorrectly detected. Depends on https://github.com/rust-lang/rust/pull/64207. changelog: Moved `redundant_clone` lint to `perf` group # What this lint catches ## `clone`/`to_owned` ```rust let s = String::new(); let t = s.clone(); ``` ```rust // MIR _1 = String::new(); _2 = &_1; _3 = clone(_2); // (*) ``` We can turn this `clone` call into a move if 1. `_2` is the sole borrow of `_1` at the statement `(*)` 2. `_1` is not used hereafter ## `Deref` + type-specific `to_owned` method ```rust let s = std::path::PathBuf::new(); let t = s.to_path_buf(); ``` ```rust // MIR _1 = PathBuf::new(); _2 = &1; _3 = call deref(_2); _4 = _3; // Copies borrow StorageDead(_2); _5 = Path::to_path_buf(_4); // (*) ``` We can turn this `to_path_buf` call into a move if 1. `_3` `_4` are the sole borrow of `_1` at `(*)` 2. `_1` is not used hereafter # What this PR introduces 1. `MaybeStorageLive` that determines whether a local lives at a particular location 2. `PossibleBorrowerVisitor` that constructs [`TransitiveRelation`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/transitive_relation/struct.TransitiveRelation.html) of possible borrows, e.g. visiting `_2 = &1; _3 = &_2:` will result in `_3 -> _2 -> _1` relation. Then `_3` and `_2` will be counted as possible borrowers of `_1` in the sole-borrow analysis above.
Diffstat (limited to 'tests/ui/map_clone.fixed')
| -rw-r--r-- | tests/ui/map_clone.fixed | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index c8b9bc04944..2029c81d0d5 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -1,7 +1,7 @@ // run-rustfix #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::iter_cloned_collect)] -#![allow(clippy::clone_on_copy)] +#![allow(clippy::clone_on_copy, clippy::redundant_clone)] #![allow(clippy::missing_docs_in_private_items)] #![allow(clippy::redundant_closure_for_method_calls)] |
