Skip to content

cannot move out of borrowed content error is bad when self is borrowed #43161

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

Open
nrc opened this issue Jul 11, 2017 · 5 comments
Open

cannot move out of borrowed content error is bad when self is borrowed #43161

nrc opened this issue Jul 11, 2017 · 5 comments
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nrc
Copy link
Member

nrc commented Jul 11, 2017

E.g., consider a struct with a field build_queue which is owned. In a &self function I call request_build which takes self by value. I get the error:

error[E0507]: cannot move out of borrowed content
   --> src/actions/mod.rs:151:9
    |
151 |         self.build_queue.request_build(project_path, priority, move |result| {
    |         ^^^^ cannot move out of borrowed content

This is not very useful since it does not indicate why a move is happening and the squiggle is indicating the wrong thing. I think the squiggle should be under self.build_queue rather than just self and that there should be a note referring to the definition of request_build and indicating the by-value self which causes the move.

@nrc nrc added A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 11, 2017
@Sekuraz
Copy link

Sekuraz commented Jul 13, 2017

Are you using self in your closure?

@nrc
Copy link
Member Author

nrc commented Jul 14, 2017

Are you using self in your closure?

No, the closure is irrelevant to this example

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank
Copy link
Contributor

estebank commented Feb 10, 2018

Repro case. No change. Should point at the reason:

error[E0507]: cannot move out of borrowed content
  --> src/main.rs:11:9
   |
3  |    fn foo(self) {}
   |    ------------ `foo` defined here
...
10 |    fn bar(&self) {
   |           ----- `self` is borrowed here
11 |         self.foo.foo();
   |         ^^^^     --- moving out of `self` because `foo(...)` moves `self.foo`
   |         |
   |         cannot move out of borrowed content

@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
@ibraheemdev
Copy link
Member

ibraheemdev commented Jul 27, 2021

@rustbot claim

@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2021

Error: Parsing assign command in comment failed: ...'bot assign' | error: specify user to assign to at >| ''...

Please let @rust-lang/release know if you're having trouble with this bot.

@ibraheemdev ibraheemdev removed their assignment Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants