Skip to content
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

When suggesting borrow, remove useless clones #61143

Merged
merged 4 commits into from Jun 15, 2019

Conversation

Projects
None yet
6 participants
@estebank
Copy link
Contributor

commented May 25, 2019

Fix #61106.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented May 25, 2019

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank estebank changed the title When suggesting to borrow, remove useless clones When suggesting borrow, remove useless clones May 25, 2019

@estebank estebank force-pushed the estebank:issue-61106 branch from 27d1c88 to 2d2d74a Jun 14, 2019

@estebank estebank force-pushed the estebank:issue-61106 branch from 2d2d74a to 8ce063a Jun 14, 2019

@oli-obk

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2019

📌 Commit 8ce063a has been approved by oli-obk

@eddyb
Copy link
Member

left a comment

r=me with trim_end_matches(".clone()") removed

@eddyb

This comment has been minimized.

Copy link
Member

commented Jun 14, 2019

@bors r-

@estebank

This comment has been minimized.

Copy link
Contributor Author

commented Jun 14, 2019

r? @eddyb @bors r=eddyb

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2019

📌 Commit 34c4117 has been approved by eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned oli-obk Jun 14, 2019

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2019

🌲 The tree is currently closed for pull requests below priority 500, this pull request will be tested once the tree is reopened

Centril added a commit to Centril/rust that referenced this pull request Jun 14, 2019

Rollup merge of rust-lang#61143 - estebank:issue-61106, r=eddyb
When suggesting borrow, remove useless clones

Fix rust-lang#61106.

bors added a commit that referenced this pull request Jun 14, 2019

Auto merge of #61850 - Centril:rollup-031fj0d, r=Centril
Rollup of 10 pull requests

Successful merges:

 - #59752 (Limit dylib symbols)
 - #61143 (When suggesting borrow, remove useless clones)
 - #61767 (Updates smallvec and new_debug_unreachable)
 - #61781 (prepare for Intptrcast model)
 - #61785 (note some safety concerns of raw-ptr-to-ref casts)
 - #61805 (typeck: Fix ICE for blocks in repeat expr count.)
 - #61813 (Remove some unnecessary symbol interner ops)
 - #61824 (in which we decline to lint single-use lifetimes in `derive`d impls)
 - #61825 (type_alias_enum_variants: fix #61801; allow a path pattern to infer)
 - #61844 (Change `...` to `..=` where applicable)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Jun 14, 2019

Rollup merge of rust-lang#61143 - estebank:issue-61106, r=eddyb
When suggesting borrow, remove useless clones

Fix rust-lang#61106.

bors added a commit that referenced this pull request Jun 14, 2019

Auto merge of #61852 - Centril:rollup-9ksf5f5, r=Centril
Rollup of 6 pull requests

Successful merges:

 - #61143 (When suggesting borrow, remove useless clones)
 - #61785 (note some safety concerns of raw-ptr-to-ref casts)
 - #61805 (typeck: Fix ICE for blocks in repeat expr count.)
 - #61813 (Remove some unnecessary symbol interner ops)
 - #61825 (type_alias_enum_variants: fix #61801; allow a path pattern to infer)
 - #61844 (Change `...` to `..=` where applicable)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Jun 14, 2019

Auto merge of #61852 - Centril:rollup-9ksf5f5, r=Centril
Rollup of 6 pull requests

Successful merges:

 - #61143 (When suggesting borrow, remove useless clones)
 - #61785 (note some safety concerns of raw-ptr-to-ref casts)
 - #61805 (typeck: Fix ICE for blocks in repeat expr count.)
 - #61813 (Remove some unnecessary symbol interner ops)
 - #61825 (type_alias_enum_variants: fix #61801; allow a path pattern to infer)
 - #61844 (Change `...` to `..=` where applicable)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2019

⌛️ Testing commit 34c4117 with merge 9f06855...

bors added a commit that referenced this pull request Jun 15, 2019

Auto merge of #61143 - estebank:issue-61106, r=eddyb
When suggesting borrow, remove useless clones

Fix #61106.
@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: eddyb
Pushing 9f06855 to master...

@bors bors added the merged-by-bors label Jun 15, 2019

@bors bors merged commit 34c4117 into rust-lang:master Jun 15, 2019

3 checks passed

Travis CI - Pull Request Build Passed
Details
homu Test successful
Details
pr Build #20190614.46 succeeded
Details
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Jun 15, 2019

📣 Toolstate changed by #61143!

Tested on commit 9f06855.
Direct link to PR: #61143

🎉 rls on linux: test-fail → test-pass (cc @Xanewok, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jun 15, 2019

📣 Toolstate changed by rust-lang/rust#61143!
Tested on commit rust-lang/rust@9f06855.
Direct link to PR: <rust-lang/rust#61143>

🎉 rls on linux: test-fail → test-pass (cc @Xanewok, @rust-lang/infra).
) {
// If this expression had a clone call when suggesting borrowing
// we want to suggest removing it because it'd now be unecessary.
sugg_sp = arg.span;

This comment has been minimized.

Copy link
@eddyb

eddyb Jun 16, 2019

Member

You should also change expr (maybe better named sugg_expr, inside the if let below?) to arg, so that the needs_parens logic, and everything else, works correctly.
(e.g. I suspect you print &1 + 2 instead of &(1 + 2) for (1 + 2).clone())

This comment has been minimized.

Copy link
@oli-obk

oli-obk Jun 27, 2019

Contributor

Nope, it works just fine:

error[E0308]: mismatched types
 --> src/main.rs:2:19
  |
2 |     let x: &i32 = (1i32 + 2).clone();
  |                   ^^^^^^^^^^^^^^^^^^
  |                   |
  |                   expected &i32, found i32
  |                   help: consider borrowing here: `&(1i32 + 2)`
  |
  = note: expected type `&i32`
             found type `i32`

This comment has been minimized.

Copy link
@eddyb

eddyb Jun 27, 2019

Member

That's mildly disturbing - the code is technically wrong, since it's looking at the whole method call when determining whether it needs parens, but happens to produce the correct result.

This comment has been minimized.

Copy link
@estebank

estebank Jun 27, 2019

Author Contributor

It's because the logic is to add parentheses to the code when it is not already int he code. In this case the parentheses are already there so the expression doesn't need to change.

This comment has been minimized.

Copy link
@eddyb

eddyb Jul 1, 2019

Member

ExprKind::Paren doesn't exist in the HIR, the first argument of the clone method call is 1i32 + 2 (which I would've assumed doesn't include parens in its own Span).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.