Skip to content

MIR borrowck: variables are still initialized after their storage ends #45642

Closed
@arielb1

Description

@arielb1

MIR borrowck considers variables still initialized after their storage ends, so if an immutable variable is defined and used in a loop, this causes an error. e.g.:

fn main() {
    loop {
        let _x = 0;
    }
}

Which causes:

$ rustc x.rs -Z borrowck-mir
error[E0384]: re-assignment of immutable variable `_x` (Mir)
 --> x.rs:3:18
  |
3 |         let _x = 0;
  |                  ^

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions