cc80106cb5
When encountering multiple mutable borrows, suggest cloning and adding derive annotations as needed. ``` error[E0596]: cannot borrow `sm.x` as mutable, as it is behind a `&` reference --> $DIR/accidentally-cloning-ref-borrow-error.rs:32:9 | LL | foo(&mut sm.x); | ^^^^^^^^^ `sm` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: `Str` doesn't implement `Clone`, so this call clones the reference `&Str` --> $DIR/accidentally-cloning-ref-borrow-error.rs:31:21 | LL | let mut sm = sr.clone(); | ^^^^^^^ help: consider annotating `Str` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | struct Str { | help: consider specifying this binding's type | LL | let mut sm: &mut Str = sr.clone(); | ++++++++++ ``` ``` error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference --> $DIR/issue-91206.rs:14:5 | LL | inner.clear(); | ^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: you can `clone` the `Vec<usize>` value and consume it, but this might not be your desired behavior --> $DIR/issue-91206.rs:11:17 | LL | let inner = client.get_inner_ref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider specifying this binding's type | LL | let inner: &mut Vec<usize> = client.get_inner_ref(); | +++++++++++++++++ ```
54 lines
1.8 KiB
Plaintext
54 lines
1.8 KiB
Plaintext
error[E0596]: cannot borrow `*rofl` as mutable, as it is behind a `&` reference
|
|
--> $DIR/issue-85765-closure.rs:7:9
|
|
|
|
|
LL | rofl.push(Vec::new());
|
|
| ^^^^ `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
|
|
|
|
help: you can `clone` the `Vec<Vec<i32>>` value and consume it, but this might not be your desired behavior
|
|
--> $DIR/issue-85765-closure.rs:4:36
|
|
|
|
|
LL | let rofl: &Vec<Vec<i32>> = &mut test;
|
|
| ^^^^^^^^^
|
|
help: consider changing this binding's type
|
|
|
|
|
LL | let rofl: &mut Vec<Vec<i32>> = &mut test;
|
|
| ~~~~~~~~~~~~~~~~~~
|
|
|
|
error[E0594]: cannot assign to `*r`, which is behind a `&` reference
|
|
--> $DIR/issue-85765-closure.rs:14:9
|
|
|
|
|
LL | *r = 0;
|
|
| ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written
|
|
|
|
|
help: consider changing this to be a mutable reference
|
|
|
|
|
LL | let r = &mut mutvar;
|
|
| +++
|
|
|
|
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
|
|
--> $DIR/issue-85765-closure.rs:21:9
|
|
|
|
|
LL | *x = 1;
|
|
| ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
|
|
|
|
|
help: consider changing this binding's type
|
|
|
|
|
LL | let x: &mut usize = &mut{0};
|
|
| ~~~~~~~~~~
|
|
|
|
error[E0594]: cannot assign to `*y`, which is behind a `&` reference
|
|
--> $DIR/issue-85765-closure.rs:28:9
|
|
|
|
|
LL | *y = 1;
|
|
| ^^^^^^ `y` is a `&` reference, so the data it refers to cannot be written
|
|
|
|
|
help: consider changing this binding's type
|
|
|
|
|
LL | let y: &mut usize = &mut(0);
|
|
| ~~~~~~~~~~
|
|
|
|
error: aborting due to 4 previous errors
|
|
|
|
Some errors have detailed explanations: E0594, E0596.
|
|
For more information about an error, try `rustc --explain E0594`.
|