-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix false-positive of redundant_clone and move to clippy::perf #4509
Conversation
☔ The latest upstream changes (presumably #4540) made this pull request unmergeable. Please resolve the merge conflicts. |
53fe3f9
to
64cea46
Compare
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why CI is failing, maybe a rustup?
6ae4a0a
to
0d6a077
Compare
0d6a077
to
4cded6d
Compare
CI passed. |
Looks good. Thank you! @bors r+ |
📌 Commit 4cded6d has been approved by |
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.
💔 Test failed - status-appveyor |
Appveyor setup seems to be broken...
|
Yeah, it unfortunately is. |
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 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 toperf
groupWhat this lint catches
clone
/to_owned
We can turn this
clone
call into a move if_2
is the sole borrow of_1
at the statement(*)
_1
is not used hereafterDeref
+ type-specificto_owned
methodWe can turn this
to_path_buf
call into a move if_3
_4
are the sole borrow of_1
at(*)
_1
is not used hereafterWhat this PR introduces
MaybeStorageLive
that determines whether a local lives at a particular locationPossibleBorrowerVisitor
that constructsTransitiveRelation
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.