Skip to content

@mut freezing bugs #5910

Closed
Closed

Description

@thestinger

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.

Activity

  1. nikomatsakis commented on May 1, 2013

    @nikomatsakis
    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.

  2. nikomatsakis commented on May 7, 2013

    @nikomatsakis
    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
    
  3. added a commit that references this issue on Aug 28, 2020
  4. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions