File: assign-non-lval-derefmut.stderr

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (66 lines) | stat: -rw-r--r-- 2,139 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
error[E0070]: invalid left-hand side of assignment
  --> $DIR/assign-non-lval-derefmut.rs:5:23
   |
LL |     x.lock().unwrap() = 2;
   |     ----------------- ^
   |     |
   |     cannot assign to this expression
   |
help: consider dereferencing here to assign to the mutably borrowed value
   |
LL |     *x.lock().unwrap() = 2;
   |     +

error[E0368]: binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>`
  --> $DIR/assign-non-lval-derefmut.rs:7:5
   |
LL |     x.lock().unwrap() += 1;
   |     -----------------^^^^^
   |     |
   |     cannot use `+=` on type `MutexGuard<'_, usize>`
   |
note: the foreign item type `MutexGuard<'_, usize>` doesn't implement `AddAssign<{integer}>`
  --> $SRC_DIR/std/src/sync/poison/mutex.rs:LL:COL
   |
   = note: not implement `AddAssign<{integer}>`
help: `+=` can be used on `usize` if you dereference the left-hand side
   |
LL |     *x.lock().unwrap() += 1;
   |     +

error[E0308]: mismatched types
  --> $DIR/assign-non-lval-derefmut.rs:11:9
   |
LL |     let mut y = x.lock().unwrap();
   |                 ----------------- expected due to this value
LL |     y = 2;
   |         ^ expected `MutexGuard<'_, usize>`, found integer
   |
   = note: expected struct `MutexGuard<'_, usize>`
                found type `{integer}`
help: consider dereferencing here to assign to the mutably borrowed value
   |
LL |     *y = 2;
   |     +

error[E0368]: binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>`
  --> $DIR/assign-non-lval-derefmut.rs:13:5
   |
LL |     y += 1;
   |     -^^^^^
   |     |
   |     cannot use `+=` on type `MutexGuard<'_, usize>`
   |
note: the foreign item type `MutexGuard<'_, usize>` doesn't implement `AddAssign<{integer}>`
  --> $SRC_DIR/std/src/sync/poison/mutex.rs:LL:COL
   |
   = note: not implement `AddAssign<{integer}>`
help: `+=` can be used on `usize` if you dereference the left-hand side
   |
LL |     *y += 1;
   |     +

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0070, E0308, E0368.
For more information about an error, try `rustc --explain E0070`.