Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tweak move error #94515

Merged
merged 1 commit into from
Mar 9, 2022
Merged

Tweak move error #94515

merged 1 commit into from
Mar 9, 2022

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Mar 2, 2022

Point at method definition that causes type to be consumed.

Fix #94056.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 2, 2022
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 2, 2022
@estebank
Copy link
Contributor Author

estebank commented Mar 2, 2022

Before

error[E0507]: cannot move out of `abc`, a captured variable in an `FnMut` closure
 --> f33.rs:3:34
  |
2 |     let mut abc = Abc { bar: Vec::new() };
  |         ------- captured outer variable
3 |     items.iter().for_each(|item| abc.update(*item));
  |                           -------^^^--------------
  |                           |      |
  |                           |      move occurs because `abc` has type `Abc`, which does not implement the `Copy` trait
  |                           captured by this `FnMut` closure

warning: variable does not need to be mutable
 --> f33.rs:2:9
  |
2 |     let mut abc = Abc { bar: Vec::new() };
  |         ----^^^
  |         |
  |         help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

error[E0382]: use of moved value: `abc`
 --> f33.rs:5:5
  |
2 |     let mut abc = Abc { bar: Vec::new() };
  |         ------- move occurs because `abc` has type `Abc`, which does not implement the `Copy` trait
3 |     items.iter().for_each(|item| abc.update(*item));
  |                           ------ --- variable moved due to use in closure
  |                           |
  |                           value moved into closure here
4 |     //~^ ERROR cannot move out of `abc`, a captured variable in an `FnMut` closure
5 |     abc //~ ERROR use of moved value: `abc`
  |     ^^^ value used here after move

After

error[E0507]: cannot move out of `abc`, a captured variable in an `FnMut` closure
  --> f33.rs:3:34
   |
2  |     let mut abc = Abc { bar: Vec::new() };
   |         ------- captured outer variable
3  |     items.iter().for_each(|item| abc.update(*item));
   |                           -------^^^--------------
   |                           |      |   |
   |                           |      |   `abc` moved due to this method call
   |                           |      move occurs because `abc` has type `Abc`, which does not implement the `Copy` trait
   |                           captured by this `FnMut` closure
   |
note: this function takes ownership of the receiver `self`, which moves `abc`
  --> f33.rs:13:19
   |
13 |     fn update(mut self, bar: u64) {
   |                   ^^^^

warning: variable does not need to be mutable
 --> f33.rs:2:9
  |
2 |     let mut abc = Abc { bar: Vec::new() };
  |         ----^^^
  |         |
  |         help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

error[E0382]: use of moved value: `abc`
 --> f33.rs:5:5
  |
2 |     let mut abc = Abc { bar: Vec::new() };
  |         ------- move occurs because `abc` has type `Abc`, which does not implement the `Copy` trait
3 |     items.iter().for_each(|item| abc.update(*item));
  |                           ------ --- variable moved due to use in closure
  |                           |
  |                           value moved into closure here
4 |     //~^ ERROR cannot move out of `abc`, a captured variable in an `FnMut` closure
5 |     abc //~ ERROR use of moved value: `abc`
  |     ^^^ value used here after move

@bors

This comment was marked as resolved.

Point at method definition that causes type to be consumed.

Fix rust-lang#94056.
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in reviewing.

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 9, 2022

📌 Commit 9875277 has been approved by davidtwco

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
@bors
Copy link
Contributor

bors commented Mar 9, 2022

⌛ Testing commit 9875277 with merge 10dccdc...

@bors
Copy link
Contributor

bors commented Mar 9, 2022

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 10dccdc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 9, 2022
@bors bors merged commit 10dccdc into rust-lang:master Mar 9, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 9, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (10dccdc): comparison url.

Summary: This benchmark run did not return any relevant results. 6 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The "this function takes ownership of the receiver self" diagnostic hint not shown inside closures
6 participants