Skip to content

error message when trying to move from an Rc or Arc is ungreat #52086

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

Closed
nikomatsakis opened this issue Jul 5, 2018 · 3 comments
Closed

error message when trying to move from an Rc or Arc is ungreat #52086

nikomatsakis opened this issue Jul 5, 2018 · 3 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

This example

use std::rc::Rc;

struct Bar { field: Vec<i32> }

fn main() {
    let x = Rc::new(Bar { field: vec![] });
    drop(x.field);
}

gives this error:

error[E0507]: cannot move out of borrowed content
 --> src/main.rs:7:10
  |
7 |     drop(x.field);
  |          ^ cannot move out of borrowed content

That is confusing -- after all, x is not borrowed!

The problem is that Rc only implements Deref, and hence we wind up lowering to Deref::deref(&x).field, and deref returns a &Bar.

We should probably say:

error[E0507]: cannot move out of `Rc`
 --> src/main.rs:7:10
  |
7 |     drop(x.field);
  |          ^ cannot move out of an `Rc`
@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll NLL-diagnostics Working towards the "diagnostic parity" goal labels Jul 5, 2018
@nikomatsakis nikomatsakis added this to the Rust 2018 Release milestone Jul 5, 2018
@nikomatsakis
Copy link
Contributor Author

This could be fixed in the (NLL) borrow check. It could maybe be fixed by altering typeck as well -- but borrowck seems perhaps easier. So I'm going to tag as an NLL bug, even though it's not specific to NLL.

@jkordish jkordish added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 11, 2018
@nikomatsakis nikomatsakis added A-NLL Area: Non-lexical lifetimes (NLL) and removed WG-compiler-nll labels Aug 27, 2018
@davidtwco davidtwco self-assigned this Sep 30, 2018
bors added a commit that referenced this issue Oct 5, 2018
error message when trying to move from an Rc or Arc is ungreat

Fixes #52086.

r? @nikomatsakis
@ta3pks
Copy link

ta3pks commented Dec 3, 2018

Seems this issue is not fixed yet despite the merge.

            let dt = std::rc::Rc::new(dt);
            let _d = dt.clone();
            for d in *_d
            {
            ...
            }

this code fails

@davidtwco
Copy link
Member

@NikosEfthias I see the intended error message with the code you've provided (playground):

error[E0507]: cannot move out of an `Rc`
 --> src/main.rs:5:15
  |
5 |     for _d in *_d {
  |               ^^^ cannot move out of an `Rc`

error: aborting due to previous error

The code you've provided should error, this issue pertains to the wording of the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working towards the "diagnostic parity" goal 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

4 participants