rust/tests/ui/suggestions/suggest-ref-mut.stderr
Esteban Küber 71b0755a98 Provide more context when mutably borrowing an imutable borrow
Point at statics and consts being mutable borrowed or written to:

```
error[E0594]: cannot assign to immutable static item `NUM`
  --> $DIR/E0594.rs:4:5
   |
LL | static NUM: i32 = 18;
   | --------------- this `static` cannot be written to
...
LL |     NUM = 20;
   |     ^^^^^^^^ cannot assign
```

Point at the expression that couldn't be mutably borrowed from a pattern:

```
error[E0596]: cannot borrow data in a `&` reference as mutable
  --> $DIR/mut-pattern-of-immutable-borrow.rs:19:14
   |
LL |     match &arg.field {
   |           ---------- this cannot be borrowed as mutable
LL |         Some(ref mut s) => s.push('a'),
   |              ^^^^^^^^^ cannot borrow as mutable
```
2025-11-09 22:14:48 +00:00

47 lines
1.5 KiB
Text

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