Skip to content

Trying to capture a local variable in a const results in an unrelated error #51375

Closed
@varkor

Description

@varkor
fn main() {
    let x: u8 = 5;
    const Y: u8 = x;
}

results in:

error[E0434]: can't capture dynamic environment in a fn item
 --> src/main.rs:3:19
  |
3 |     const Y: u8 = x;
  |                   ^
  |
  = help: use the `|| { ... }` closure form instead

error: aborting due to previous error

(which of course doesn't work — actually carrying out the suggestion results in the same suggestion).

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions