Skip to content

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

@msullivan

Description

@msullivan

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.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions