Skip to content

Provide #[diagnostic::on_move(message)] for smart pointers to explain why they aren't Copy and what to do instead #149862

Description

@estebank

Given a situation like #149861 where we emit

error[E0382]: use of moved value: `results`
  --> src/main.rs:30:22
   |
22 |     let results = Arc::new(Mutex::new(Vec::new()));
   |         ------- move occurs because `results` has type `Arc<std::sync::Mutex<Vec<i32>>>`, which does not implement the `Copy` trait
...
28 |     for i in 0..20 {
   |     -------------- inside of this loop
29 |         // let results = Arc::clone(&results);
30 |         pool.execute(move || {
   |                      ^^^^^^^ value moved into closure here, in previous iteration of loop
31 |             let mut r = results.lock().unwrap();
   |                         ------- use occurs due to use in closure
...

we should have a way of annotating Arc to explain that even though it isn't Copy, you can cheaply clone it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions