Skip to content

MIR-borrowck: assignment to static mut shouldn't be an error #45641

Closed
@arielb1

Description

@arielb1

MIR borrowck errors out on assignments to mutable statics, which should be allowed (in unsafe code) e.g.

static mut Y: u32 = 0;

unsafe fn should_ok() {
    Y = 1;
}

fn main() {}

which causes:

$ rustc x.rs -Z borrowck-mir
error: cannot assign to immutable static item Y (Mir)
 --> x.rs:5:5
  |
5 |     Y = 1;
  |     ^^^^^

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions