Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point to immutable arg/fields when trying to use as &mut #39139

Merged
merged 1 commit into from
Jan 27, 2017

Commits on Jan 26, 2017

  1. Point to immutable arg/fields when trying to use as &mut

    Point to immutable borrow arguments and fields when trying to use them as
    mutable borrows. Add label to primary span on "cannot borrow as mutable"
    errors.
    
    Present the following output when trying to access an immutable borrow's
    field as mutable:
    
    ```
    error[E0389]: cannot borrow data mutably in a `&` reference
      --> $DIR/issue-38147-1.rs:27:9
       |
    26 | fn f(&self) {
       |      -----  use `&mut self` here to make mutable
    27 |     f.s.push('x');
       |     ^^^ assignment into an immutable reference
    ```
    
    And the following when trying to access an immutable struct field as mutable:
    
    ```
    error: cannot borrow immutable borrowed content `*self.s` as mutable
      --> $DIR/issue-38147-3.rs:17:9
       |
    12 |     s: &'a String
       |     ------------- use `&'a mut String` here to make mutable
    ...|
    16 |     fn f(&self) {
       |          -----  use `&mut self` here to make mutable
    17 |         self.s.push('x');
       |         ^^^^^^ cannot borrow as mutable
    ```
    estebank committed Jan 26, 2017
    Configuration menu
    Copy the full SHA
    e1280d8 View commit details
    Browse the repository at this point in the history