Skip to content

Improve E0389 "cannot borrow data mutably in a & reference" error message #38147

Closed
@mikhail-m1

Description

@mikhail-m1

Error in next case could be more helpful

struct Foo<'a> {
    s: &'a mut String
}

impl<'a> Foo<'a> {
    fn f(&self) {
        self.s.push('x');
    }
}

fn main() {}

error:

error[E0389]: cannot borrow data mutably in a `&` reference
 --> 2.rs:7:9
  |
7 |         self.s.push('x');
  |         ^^^^^^ assignment into an immutable reference

cc @jonathandturner

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