Also test `&mut self` suggestion

This commit is contained in:
ashtneoi 2018-07-11 03:45:25 -07:00
parent 73a979ad63
commit 77d5f39771
2 changed files with 24 additions and 4 deletions

View File

@ -10,6 +10,17 @@
#![feature(nll)]
struct X(usize);
impl X {
fn zap(&self) {
//~^ HELP
//~| SUGGESTION &mut self
self.0 = 32;
//~^ ERROR
}
}
fn main() {
let ref foo = 16;
//~^ HELP

View File

@ -1,5 +1,14 @@
error[E0594]: cannot assign to `self.0` which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:19:9
|
LL | fn zap(&self) {
| ----- help: consider changing this to be a mutable reference: `&mut self`
...
LL | self.0 = 32;
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*foo` which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:17:5
--> $DIR/suggest-ref-mut.rs:28:5
|
LL | let ref foo = 16;
| ------- help: consider changing this to be a mutable reference: `ref mut foo`
@ -8,7 +17,7 @@ LL | *foo = 32;
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*bar` which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:22:9
--> $DIR/suggest-ref-mut.rs:33:9
|
LL | if let Some(ref bar) = Some(16) {
| ------- help: consider changing this to be a mutable reference: `ref mut bar`
@ -17,13 +26,13 @@ LL | *bar = 32;
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*quo` which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:26:22
--> $DIR/suggest-ref-mut.rs:37:22
|
LL | ref quo => { *quo = 32; },
| ------- ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written
| |
| help: consider changing this to be a mutable reference: `ref mut quo`
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0594`.