Skip to content

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

Closed
@nikomatsakis

Description

@nikomatsakis

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`

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions