Skip to content

Rollup of 2 pull requests - #4625

Merged
bors merged 10 commits into
rust-lang:masterfrom
phansch:rollup-qp7ki0h
Oct 4, 2019
Merged

Rollup of 2 pull requests#4625
bors merged 10 commits into
rust-lang:masterfrom
phansch:rollup-qp7ki0h

Conversation

@phansch

@phansch phansch commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

Successful merges:

Failed merges:

changelog: none

r? @ghost

HMPerson1 and others added 10 commits October 2, 2019 17:23
Co-Authored-By: ecstatic-morse <ecstaticmorse@gmail.com>
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.
Allow casts from the result of `abs` to unsigned

changelog: Allow casts from the result of `abs` to unsigned in `cast_sign_loss`

Fixes rust-lang#4605
@phansch

phansch commented Oct 4, 2019

Copy link
Copy Markdown
Contributor Author

@bors r+

@bors

bors commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

📌 Commit 19c58d2 has been approved by phansch

bors added a commit that referenced this pull request Oct 4, 2019
Rollup of 2 pull requests

Successful merges:

 - #4509 (Fix false-positive of redundant_clone and move to clippy::perf)
 - #4614 (Allow casts from the result of `abs` to unsigned)

Failed merges:

r? @ghost
@bors

bors commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

⌛ Testing commit 19c58d2 with merge 0ccf629...

@bors

bors commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

💔 Test failed - checks-travis

@phansch

phansch commented Oct 4, 2019

Copy link
Copy Markdown
Contributor Author

@bors retry (changelog: none)

@bors

bors commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

⌛ Testing commit 19c58d2 with merge 249b6ca...

bors added a commit that referenced this pull request Oct 4, 2019
Rollup of 2 pull requests

Successful merges:

 - #4509 (Fix false-positive of redundant_clone and move to clippy::perf)
 - #4614 (Allow casts from the result of `abs` to unsigned)

Failed merges:

changelog: none

r? @ghost
@bors

bors commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

☀️ Test successful - checks-travis, status-appveyor
Approved by: phansch
Pushing 249b6ca to master...

@bors
bors merged commit 19c58d2 into rust-lang:master Oct 4, 2019
@bors bors mentioned this pull request Oct 4, 2019
@phansch
phansch deleted the rollup-qp7ki0h branch October 4, 2019 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants