Skip to content

borrowck compiler errors for upvars contain "spurious" dereferences #46003

Description

@arielb1

STR

fn main() {
    let mut y = 0;
    || {
        let b = &y;
        y += 1;
        *b
    };
}

Result

error[E0506]: cannot assign to `**y` because it is borrowed
 --> src/main.rs:5:9
  |
4 |         let b = &y;
  |                  - borrow of `**y` occurs here
5 |         y += 1;
  |         ^^^^^^ assignment to borrowed `**y` occurs here

error: aborting due to previous error

y is an integer, so **y isn't actually a thing. We emit the dereferences because there are layers of indirection before we get to the upvar, but they aren't actually a part of the user-visible syntax.

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 lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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