]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #40445 - estebank:issue-18150, r=jonathandturner
authorCorey Farwell <coreyf@rwell.org>
Sun, 19 Mar 2017 14:18:13 +0000 (10:18 -0400)
committerGitHub <noreply@github.com>
Sun, 19 Mar 2017 14:18:13 +0000 (10:18 -0400)
Point to let when modifying field of immutable variable

Point at the immutable local variable when trying to modify one of its
fields.

Given a file:

```rust
struct Foo {
    pub v: Vec<String>
}

fn main() {
    let f = Foo { v: Vec::new() };
    f.v.push("cat".to_string());
}
```

present the following output:

```
error: cannot borrow immutable field `f.v` as mutable
 --> file.rs:7:13
  |
6 |    let f = Foo { v: Vec::new() };
  |        - this should be `mut`
7 |    f.v.push("cat".to_string());
  |    ^^^

error: aborting due to previous error
```

Fix #27593.

1  2 
src/librustc/middle/mem_categorization.rs
src/librustc_borrowck/borrowck/mod.rs

Simple merge