Skip to content

Demotion to const ptr leads to confusing error message #2949

Closed
@jruderman

Description

@jruderman
fn main()
{
    let mut x = ~mut 3;
    assert *x == 3;
    *x = 4;
    assert *x == 4;
    x = ~5;
    assert *x == 5;
}

gives me a somewhat confusing error

1.rs:5:4: 5:6 error: assigning to dereference of const ~ pointer
1.rs:5     *x = 4;
           ^~

Took me a while to figure out that the last assignment was forcing x to become a const ptr for its entire life. That was my mistake, but causing an error earlier in the function threw me off. It would be nice if the compiler explained why the type of x was not what it appeared to be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions