Skip to content

Cannot assign twice to immutable variable with 'l: while break 'l {} as initializer #62115

Closed

Description

@Centril

With:

fn _f() {
    let _x = 'label: while break 'label {};
}

we get:

warning[E0384]: cannot assign twice to immutable variable `_x`
 --> src/lib.rs:2:14
  |
2 |     let _x = 'label: while break 'label {};
  |         --   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
  |         |
  |         first assignment to `_x`
  |         help: make this binding mutable: `mut _x`
  |
  = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
  = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
  = note: for more information, try `rustc --explain E0729`

This seems wrong. At least from a source view, _x is assigned to once.

Current MIR dump:

fn  _f() -> () {
    let mut _0: ();                      // return place in scope 0 at src/lib.rs:1:9: 1:9
    let _1: ();                          // "_x" in scope 0 at src/lib.rs:2:9: 2:11
    scope 1 {
    }

    bb0: {
        StorageLive(_1);                 // bb0[0]: scope 0 at src/lib.rs:2:9: 2:11
        StorageDead(_1);                 // bb0[1]: scope 0 at src/lib.rs:3:1: 3:2
        return;                          // bb0[2]: scope 0 at src/lib.rs:3:2: 3:2
    }
}

This might possibly be fixed by #61988.

cc @eddyb @pnkfelix @matthewjasper

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-NLLArea: Non-lexical lifetimes (NLL)
    C-bugCategory: This is a bug.
    on Jun 25, 2019
  2. pnkfelix commented on Jun 25, 2019

    @pnkfelix
    Contributor

    @eddyb points out that the first bullet item of PR #61872 says that it fixes this.

  3. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Jun 25, 2019
  4. Centril commented on Jun 25, 2019

    @Centril
    ContributorAuthor
  5. eddyb commented on Jun 25, 2019

    @eddyb
    Contributor

    @Centril once it's merged? @matthewjasper could add this test and close this issue as part of the PR.

  6. added a commit that references this issue on Jun 26, 2019
    d3e2cec
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-NLLArea: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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