Skip to content

Confusing error message: dereference of &-pointer #17561

Closed
@steveklabnik

Description

@steveklabnik

This code:

fn main() {
    let bar = &5;
    foo(&*bar);
}

fn foo(x: &mut int) -> &int {
    x
}

Gives this error message:

hello.rs:3:9: 3:14 error: cannot borrow immutable dereference of `&`-pointer as mutable
hello.rs:3     foo(&*bar);
                   ^~~~~

This error is correct, but is really complicated. First of all, &pointer should probably use 'reference,' the term we've settled on for &T. More importantly, it's just a very dense sentence. This came up in IRC this morning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions