Skip to content

Borrow checker is too strict for ~mut vecs #4331

Description

@sophiebits

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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