Skip to content

"assigning... prohibited due to outstanding loan" could be clearer #2969

Closed
@jruderman

Description

fn main()
{
   let mut x = [mut 1, 2, 4];
   let v : &int = &x[2];
   x[2] = 6;
   assert *v == 6;
}

gives me

/Users/jruderman/Desktop/a.rs:5:3: 5:6 error: assigning to mutable vec content prohibited due to outstanding loan
/Users/jruderman/Desktop/a.rs:5    x[2] = 6;
                                   ^~~
/Users/jruderman/Desktop/a.rs:4:19: 4:22 note: loan of mutable vec content granted here
/Users/jruderman/Desktop/a.rs:4    let v : &int = &x[2];
                                                   ^~~

I think the error message should emphasize that it is an immutable loan. So it's clear that if you were to change it to a mutable loan, it's okay.

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions