Skip to content

Bad error message for missing DerefMut #21536

Closed
@kmcallister

Description

@kmcallister
use std::ops::{Deref, DerefMut};

struct Foo(u32);

impl Deref for Foo {
    type Target = u32;
    fn deref<'a>(&'a self) -> &'a u32 { &self.0 }
}

/*
impl DerefMut for Foo {
    fn deref_mut<'a>(&'a mut self) -> &'a mut u32 { &mut self.0 }
}
*/

fn main() {
    let mut foo = Foo(3);
    *foo = 4;
}

gives

foo.rs:18:5: 18:13 error: cannot assign to immutable borrowed content
foo.rs:18     *foo = 4;
              ^~~~~~~~

which is not too helpful. We shouldn't even try to borrow immutably in this case. Or at least tag the borrow with some metadata saying DerefMut wasn't available, so we can print a help: message here.

rustc 1.0.0-dev (ed530d7 2015-01-16 22:41:16 +0000)

Not sure this is actually easy to fix, but I think it'd be a good beginner project to spend a little time looking into it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions