Skip to content

@mut freezing bugs #5910

New issue

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

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

Already on GitHub? # to your account

Closed
thestinger opened this issue Apr 16, 2013 · 2 comments
Closed

@mut freezing bugs #5910

thestinger opened this issue Apr 16, 2013 · 2 comments
Assignees

Comments

@thestinger
Copy link
Contributor

You can unfreeze with a temporary borrowed pointer, because it doesn't restore the previous state:

fn main() {
    let x = @mut 5;

    let a = &*x;
    {
        let b = &*x;
    }
    let c = &mut *x;
}

Mutable borrows aren't tracked:

fn main() {
    let x = @mut 5;

    let a = &mut *x;
    let b = &mut *x;
    let c = &*x;
}

I think freezing needs to be enum Borrow { Mutable, Immutable, Nothing } with an immutable borrow failing if there was a Mutable one, and a mutable borrow failing on any freeze.

@ghost ghost assigned nikomatsakis Apr 16, 2013
@nikomatsakis
Copy link
Contributor

Yeah, this code is not really right. I have some parts of this fixed in my borrow checker branch, and I've started a branch to take care of the rest.

bors added a commit that referenced this issue May 7, 2013
…omatsakis

This rather sprawling branch refactors the borrow checker and much of the region code, addressing a number of outstanding issues. I will close them manually after validating that there are test cases for each one, but here is a (probably partial) list:

  - #4903: Flow sensitivity
  - #3387: Moves in overloaded operators
  - #3850: Region granularity
  - #4666: Odd loaning errors
  - #6021: borrow check errors with hashmaps
  - #5910: @mut broken

cc #5047

(take 5)
@nikomatsakis
Copy link
Contributor

These issues are resolved. See the following run-pass and run-fail tests:

run-pass:
borrowck-wg-borrow-mut-to-imm-2.rs
borrowck-wg-borrow-mut-to-imm-3.rs
borrowck-wg-borrow-mut-to-imm.rs
borrowck-wg-simple.rs
borrowck-wg-two-imm-borrows.rs

run-fail:
borrowck-wg-fail-2.rs
borrowck-wg-fail-3.rs
borrowck-wg-fail.rs
borrowck-wg-imm-then-mut.rs
borrowck-wg-mut-then-imm.rs
borrowck-wg-one-mut-one-imm.rs
borrowck-wg-one-mut-one-imm-slice-method.rs
borrowck-wg-one-mut-one-imm-slices.rs
borrowck-wg-two-array-indices.rs

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants