Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Borrow checker is too strict for ~mut vecs #4331

Closed
spicyj opened this Issue · 2 comments

2 participants

@spicyj

This code

fn impure_fn(_: &[int]) { }

fn takes_a_borrowed_ptr(v: & ~mut [int]) {
    impure_fn(*v);
}

fails to compile with the error

error: illegal borrow unless pure: creating immutable alias to mutable vec content
impure_fn(*v);
          ^~
note: impure due to access to impure function
impure_fn(*v);
^~~~~~~~~

This seems wrong to me because this function compiles fine:

fn takes_an_owned_vec(v: ~mut [int]) {
    impure_fn(v);
}

Neither one will compile if the ~mut are changed to @mut (both give the same error as I already quoted), which makes sense to me.

Apologies if I'm missing something obvious here.

@nikomatsakis
Owner

This is behaving as designed: the unique vector is accessed through a copyable, aliasable pointer, hence the unique vector resides is aliasable too from the compiler's POV.

@spicyj

I see, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.