Skip to content

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

@estebank

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.

Metadata

Metadata

Assignees

No one assigned

    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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions