Skip to content

Best-effort checks for @mut freezing are *too* conservative #6361

Closed
@nikomatsakis

Description

@nikomatsakis

This test fails to compile but should not:

fn take_mut_slice<'a>(v: &'a mut [int]) -> &'a int { &v[0] }

fn main() {
    let mut x: ~[@mut [int]] = ~[@mut [3], @mut [4]];
    let a = take_mut_slice(x[0]);
    let b = take_mut_slice(x[1]);
    *a + *b;
}

I get the following errors:

/home/nmatsakis/tmp/best-effort.rs:6:27: 6:30 error: cannot borrow `(*(*x)[])[]` as mutable more than once at at a time                                          
/home/nmatsakis/tmp/best-effort.rs:6     let b = take_mut_slice(x[1]);
                                                                ^~~
/home/nmatsakis/tmp/best-effort.rs:5:27: 5:30 note: second borrow of `(*(*x)[])[]` as mutable occurs here                                                        
/home/nmatsakis/tmp/best-effort.rs:5     let a = take_mut_slice(x[0]);
                                                                ^~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions