Skip to content

NLL: error from get-opts crate #47707

Closed
Closed
@nikomatsakis

Description

@nikomatsakis

In #47596, @SimonSapin reported several NLL errors in dependencies of the servo crate. @lqd later minimized one of those errors into this example:

#![feature(nll)]

enum SplitWithinState { A, B }

fn each_split_within() {
    let mut state = SplitWithinState::A;
    let mut closure = || { state = SplitWithinState::A };
    if let SplitWithinState::A = state {
    }
    closure();
}

fn main() {}

which yields:

error[E0503]: cannot use `state` because it was mutably borrowed
 --> src/main.rs:8:12
  |
7 |     let mut closure = || { state = SplitWithinState::A };
  |                       ---------------------------------- borrow of `state` occurs here
8 |     if let SplitWithinState::A = state {
  |            ^^^^^^^^^^^^^^^^^^^ use of borrowed `state`

error: aborting due to previous error

That said, at first glance, this looks like it might be a bug fix -- the closure is assigning to state, so it has a mutable borrow, and the if let is testing it. Pretty sure this is #45045.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions