Fix false-positive of redundant_clone and move to clippy::perf#4509
Merged
bors merged 7 commits intorust-lang:masterfrom Oct 4, 2019
Merged
Fix false-positive of redundant_clone and move to clippy::perf#4509bors merged 7 commits intorust-lang:masterfrom
bors merged 7 commits intorust-lang:masterfrom
Conversation
Contributor
|
☔ The latest upstream changes (presumably #4540) made this pull request unmergeable. Please resolve the merge conflicts. |
53fe3f9 to
64cea46
Compare
tmandry
added a commit
to tmandry/rust
that referenced
this pull request
Sep 18, 2019
Make rustc_mir::dataflow module pub (for clippy) I'm working on fixing false-positives of a MIR-based clippy lint (rust-lang/rust-clippy#4509), and in need of the dataflow infrastructure.
7ef97d7 to
a435739
Compare
oli-obk
reviewed
Sep 28, 2019
Contributor
oli-obk
left a comment
There was a problem hiding this comment.
Sorry, totally forgot about this.
The impl lgtm. Just a nit and if you have the time some docs would be great.
107c161 to
6ae4a0a
Compare
oli-obk
approved these changes
Sep 30, 2019
Contributor
oli-obk
left a comment
There was a problem hiding this comment.
not sure why CI is failing, maybe a rustup?
6ae4a0a to
0d6a077
Compare
Co-Authored-By: ecstatic-morse <ecstaticmorse@gmail.com>
0d6a077 to
4cded6d
Compare
Contributor
Author
|
CI passed. |
Contributor
|
Looks good. Thank you! @bors r+ |
Contributor
|
📌 Commit 4cded6d has been approved by |
Contributor
bors
added a commit
that referenced
this pull request
Oct 3, 2019
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 rust-lang/rust#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.
Contributor
|
💔 Test failed - status-appveyor |
Contributor
Author
|
Appveyor setup seems to be broken... |
Contributor
|
Yeah, it unfortunately is. |
phansch
added a commit
to phansch/rust-clippy
that referenced
this pull request
Oct 4, 2019
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 rust-lang/rust#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces dataflow analysis to
redundant_clonelint to filter out borrowed variables, which had been incorrectly detected.Depends on rust-lang/rust#64207.
changelog: Moved
redundant_clonelint toperfgroupWhat this lint catches
clone/to_ownedWe can turn this
clonecall into a move if_2is the sole borrow of_1at the statement(*)_1is not used hereafterDeref+ type-specificto_ownedmethodWe can turn this
to_path_bufcall into a move if_3_4are the sole borrow of_1at(*)_1is not used hereafterWhat this PR introduces
MaybeStorageLivethat determines whether a local lives at a particular locationPossibleBorrowerVisitorthat constructsTransitiveRelationof possible borrows, e.g. visiting_2 = &1; _3 = &_2:will result in_3 -> _2 -> _1relation. Then_3and_2will be counted as possible borrowers of_1in the sole-borrow analysis above.