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 definition when modifying field of immutable variable #40767

Closed
wants to merge 1 commit into from

Commits on Mar 24, 2017

  1. Point to definition when modifying field of immutable variable

    Given a file
    
    ```rust
    struct S {
        x: i32,
    }
    fn foo() {
        let s = S { x: 42 };
        s.x += 1;
    }
    fn bar(s: S) {
        s.x += 1;
    }
    ```
    
    Provide the following output:
    
    ```rust
    error: cannot assign to immutable field `s.x`
     --> $DIR/issue-35937.rs:16:5
      |
    5 |     let s = S { x: 42 };
      |         - consider changing this to `mut s`
    6 |     s.x += 1;
      |     ^^^^^^^^ cannot mutably borrow immutable field
    
    error: cannot assign to immutable field `s.x`
     --> $DIR/issue-35937.rs:20:5
      |
    8 | fn bar(s: S) {
      |        - consider changing this to `mut s`
    9 |     s.x += 1;
      |     ^^^^^^^^ cannot mutably borrow immutable field
    ```
    
    Follow up to rust-lang#40445. Fix rust-lang#35937.
    estebank committed Mar 24, 2017
    Configuration menu
    Copy the full SHA
    289772f View commit details
    Browse the repository at this point in the history