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

Borrow check doesn't properly deal with references into mutable record fields #3162

Closed
msullivan opened this issue Aug 9, 2012 · 2 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system
Milestone

Comments

@msullivan
Copy link
Contributor

The following code compiles and outputs &10.

fn each<T>(x: &[T], op: fn(elem: &T) -> bool) {
    uint::range(0, x.len(), |i| op(&x[i]));
}

fn main() {
    let x = ~[{mut a: 0}];
    for each(x) |y| {
        let z = &y.a;
        x[0].a = 10;
        log(error, z);
    }
}

It also fails if you use vec::each, which uses reference modes instead of region pointers. It should be rejected.

@nikomatsakis
Copy link
Contributor

Actually the fix was wrong. I have a pending more correct fix.

@nikomatsakis
Copy link
Contributor

Should be fixed for real now.

catamorphism pushed a commit to catamorphism/rust that referenced this issue Oct 8, 2012
saethlin pushed a commit to saethlin/rust that referenced this issue Nov 17, 2023
share getentropy shim across various unixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants