about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-03-19 10:18:13 -0400
committerGitHub <noreply@github.com>2017-03-19 10:18:13 -0400
commit9032ceae979b6fc0e74f1a3db62222eb1cfce886 (patch)
tree9bfc0191a6c1e885360dacaa32f1c01e4e9f42f1 /src/test
parent7b686ce4caa65efb96a9a00062d7d408f6d475cd (diff)
parent9ac628d5e84bd3664e41d53bafa3d66b303b19c1 (diff)
Rollup merge of #40445 - estebank:issue-18150, r=jonathandturner
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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/did_you_mean/issue-39544.stderr4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/test/ui/did_you_mean/issue-39544.stderr b/src/test/ui/did_you_mean/issue-39544.stderr
index c0088f39ad3..7f124e6d34d 100644
--- a/src/test/ui/did_you_mean/issue-39544.stderr
+++ b/src/test/ui/did_you_mean/issue-39544.stderr
@@ -1,8 +1,10 @@
 error: cannot borrow immutable field `z.x` as mutable
   --> $DIR/issue-39544.rs:21:18
    |
+20 |     let z = Z { x: X::Y };
+   |         - consider changing this to `mut z`
 21 |     let _ = &mut z.x;
-   |                  ^^^
+   |                  ^^^ cannot mutably borrow immutable field
 
 error: aborting due to previous error