Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arielb1 opened this issue Oct 30, 2017 · 3 comments
Closed

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

arielb1 opened this issue Oct 30, 2017 · 3 comments
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug.
Milestone

Comments

@arielb1
Copy link
Contributor

arielb1 commented Oct 30, 2017

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
@arielb1 arielb1 added A-borrow-checker Area: The borrow checker WG-compiler-nll labels Oct 30, 2017
@TimNN TimNN added the C-bug Category: This is a bug. label Oct 31, 2017
@nikomatsakis
Copy link
Contributor

Seems like this ought to fall out from permissions checking (#44837), right?

@arielb1 arielb1 added this to the NLL prototype milestone Nov 15, 2017
@arielb1
Copy link
Contributor Author

arielb1 commented Nov 15, 2017

Nope, still broken in 88a28ff (which includes #44837)

@KiChjang
Copy link
Member

Looking at this as well. I believe the error comes from the improper static check in check_if_reassignment_to_immutable_state.

bors added a commit that referenced this issue Nov 18, 2017
Ignore borrowck for static lvalues and allow assignment to static muts

Fixes #45129.
Fixes #45641.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants