Skip to content

Slightly incorrect error on mutable borrow of immutable captured variable #18330

Description

@bkoropoff

Code:

fn set(x: &mut usize) { *x = 1; }

fn main() {
    let x = 0;
    || set(&mut x);
}

Output:

<anon>:7:5: 7:19 error: closure cannot assign to immutable local variable `x`
<anon>:7     || set(&mut x);
             ^~~~~~~~~~~~~~

This should actually state that it cannot borrow (rather than assign) the variable. This has been around since 0.10 at least.

Activity

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

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions