about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-10-01 19:20:57 +0200
committerDavid Wood <david@davidtw.co>2018-10-02 00:35:15 +0200
commit2be306939dae233ae641ebd692ef45840bb419cb (patch)
tree8c880476d12eaf47c4fd5ca31a9b242c95eef539 /src/test
parent43b5d725d0b458e317c52ef200d323998fa0c20f (diff)
downloadrust-2be306939dae233ae641ebd692ef45840bb419cb.tar.gz
rust-2be306939dae233ae641ebd692ef45840bb419cb.zip
Improve mutability error suggestions.
This commit improves mutability error suggestions by suggesting the
removal of `&mut` where a mutable borrow is being taken of a `&mut self`
or a `self: &mut Self`.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/did_you_mean/issue-31424.nll.stderr12
-rw-r--r--src/test/ui/nll/issue-51191.rs11
-rw-r--r--src/test/ui/nll/issue-51191.stderr28
3 files changed, 32 insertions, 19 deletions
diff --git a/src/test/ui/did_you_mean/issue-31424.nll.stderr b/src/test/ui/did_you_mean/issue-31424.nll.stderr
index eae834e2b1a..15139e4e8ae 100644
--- a/src/test/ui/did_you_mean/issue-31424.nll.stderr
+++ b/src/test/ui/did_you_mean/issue-31424.nll.stderr
@@ -2,15 +2,19 @@ error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
   --> $DIR/issue-31424.rs:17:9
    |
 LL |         (&mut self).bar(); //~ ERROR cannot borrow
-   |         ^^^^^^^^^^^ cannot borrow as mutable
+   |         ^^^^^^^^^^^
+   |         |
+   |         cannot borrow as mutable
+   |         try removing `&mut` here
 
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
   --> $DIR/issue-31424.rs:23:9
    |
-LL |     fn bar(self: &mut Self) {
-   |            ---- help: consider changing this to be mutable: `mut self`
 LL |         (&mut self).bar(); //~ ERROR cannot borrow
-   |         ^^^^^^^^^^^ cannot borrow as mutable
+   |         ^^^^^^^^^^^
+   |         |
+   |         cannot borrow as mutable
+   |         try removing `&mut` here
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/nll/issue-51191.rs b/src/test/ui/nll/issue-51191.rs
index 3dd6c629fc7..87ec3e5df0b 100644
--- a/src/test/ui/nll/issue-51191.rs
+++ b/src/test/ui/nll/issue-51191.rs
@@ -14,11 +14,13 @@ struct Struct;
 
 impl Struct {
     fn bar(self: &mut Self) {
-        (&mut self).bar(); //~ ERROR cannot borrow
+        (&mut self).bar();
+        //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
     }
 
     fn imm(self) {
-        (&mut self).bar(); //~ ERROR cannot borrow
+        (&mut self).bar();
+        //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
     }
 
     fn mtbl(mut self) {
@@ -26,11 +28,14 @@ impl Struct {
     }
 
     fn immref(&self) {
-        (&mut self).bar(); //~ ERROR cannot borrow
+        (&mut self).bar();
+        //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
+        //~^^ ERROR cannot borrow data in a `&` reference as mutable [E0596]
     }
 
     fn mtblref(&mut self) {
         (&mut self).bar();
+        //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable [E0596]
     }
 }
 
diff --git a/src/test/ui/nll/issue-51191.stderr b/src/test/ui/nll/issue-51191.stderr
index e56ddb1ed53..c5b5218f173 100644
--- a/src/test/ui/nll/issue-51191.stderr
+++ b/src/test/ui/nll/issue-51191.stderr
@@ -1,36 +1,40 @@
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
   --> $DIR/issue-51191.rs:17:9
    |
-LL |     fn bar(self: &mut Self) {
-   |            ---- help: consider changing this to be mutable: `mut self`
-LL |         (&mut self).bar(); //~ ERROR cannot borrow
-   |         ^^^^^^^^^^^ cannot borrow as mutable
+LL |         (&mut self).bar();
+   |         ^^^^^^^^^^^
+   |         |
+   |         cannot borrow as mutable
+   |         try removing `&mut` here
 
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
-  --> $DIR/issue-51191.rs:21:9
+  --> $DIR/issue-51191.rs:22:9
    |
 LL |     fn imm(self) {
    |            ---- help: consider changing this to be mutable: `mut self`
-LL |         (&mut self).bar(); //~ ERROR cannot borrow
+LL |         (&mut self).bar();
    |         ^^^^^^^^^^^ cannot borrow as mutable
 
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
-  --> $DIR/issue-51191.rs:29:9
+  --> $DIR/issue-51191.rs:31:9
    |
-LL |         (&mut self).bar(); //~ ERROR cannot borrow
+LL |         (&mut self).bar();
    |         ^^^^^^^^^^^ cannot borrow as mutable
 
 error[E0596]: cannot borrow data in a `&` reference as mutable
-  --> $DIR/issue-51191.rs:29:9
+  --> $DIR/issue-51191.rs:31:9
    |
-LL |         (&mut self).bar(); //~ ERROR cannot borrow
+LL |         (&mut self).bar();
    |         ^^^^^^^^^^^ cannot borrow as mutable
 
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
-  --> $DIR/issue-51191.rs:33:9
+  --> $DIR/issue-51191.rs:37:9
    |
 LL |         (&mut self).bar();
-   |         ^^^^^^^^^^^ cannot borrow as mutable
+   |         ^^^^^^^^^^^
+   |         |
+   |         cannot borrow as mutable
+   |         try removing `&mut` here
 
 error: aborting due to 5 previous errors