Skip to content

Conflicting help messages for dereferencing and moving non-Copy values #154826

@naskya

Description

@naskya

Code

use std::sync::LazyLock;

static V: LazyLock<(Vec<u8>,)> = LazyLock::new(|| (vec![],));

fn main() {
    let (v,) = *V;
    let _: &Vec<_> = &v;
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of dereference of `LazyLock<(Vec<u8>,)>`
 --> src/main.rs:6:16
  |
6 |     let (v,) = *V;
  |          -     ^^
  |          |
  |          data moved here
  |          move occurs because `v` has type `Vec<u8>`, which does not implement the `Copy` trait
  |
help: consider removing the dereference here
  |
6 -     let (v,) = *V;
6 +     let (v,) = V;
  |

For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` (bin "playground") due to 1 previous error

However, after applying this suggestion (*VV) and recompiling:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:6:9
  |
6 |     let (v,) = V;
  |         ^^^^   - this expression has type `LazyLock<(Vec<u8>,)>`
  |         |
  |         expected `LazyLock<(Vec<u8>,)>`, found `(_,)`
  |
  = note: expected struct `LazyLock<(Vec<u8>,)>`
              found tuple `(_,)`
help: consider dereferencing to access the inner value using the Deref trait
  |
6 |     let (v,) = *V;
  |                +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

The compiler should provide a consistent and actionable suggestion. For example, it could suggest borrowing instead of moving (e.g., let (v,) = &*V or similar), or otherwise guide the user toward a correct pattern without contradiction.

Rationale and extra context

No response

Other cases

Rust Version

Confirmed on the Playground with the latest versions:

  • stable: 1.94.1
  • beta: 1.95.0-beta.7 (2026-04-03 cc969f3)
  • nightly: 1.96.0-nightly (2026-04-03 2972b5e)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions