blob: 7f8cc74a7157a695bfa7b45fe47776384e97b5ec [file] [log] [blame]
Inna Palantff3f07a2019-07-11 16:15:26 -07001error[E0505]: cannot move out of `s` because it is borrowed
2 --> $DIR/borrowck-overloaded-index-move-index.rs:50:22
3 |
Chris Wailes5c0824a2023-04-24 16:30:59 -07004LL | let mut s = "hello".to_string();
5 | ----- binding `s` declared here
Inna Palantff3f07a2019-07-11 16:15:26 -07006LL | let rs = &mut s;
Matthew Maurer7ae0b872019-09-05 14:14:26 -07007 | ------ borrow of `s` occurs here
Chris Wailes65720582022-08-11 09:53:28 -07008LL |
Inna Palantff3f07a2019-07-11 16:15:26 -07009LL | println!("{}", f[s]);
10 | ^ move out of `s` occurs here
Matthew Maurer7ae0b872019-09-05 14:14:26 -070011...
12LL | use_mut(rs);
13 | -- borrow later used here
Inna Palantff3f07a2019-07-11 16:15:26 -070014
15error[E0505]: cannot move out of `s` because it is borrowed
16 --> $DIR/borrowck-overloaded-index-move-index.rs:53:7
17 |
Chris Wailes5c0824a2023-04-24 16:30:59 -070018LL | let mut s = "hello".to_string();
19 | ----- binding `s` declared here
Inna Palantff3f07a2019-07-11 16:15:26 -070020LL | let rs = &mut s;
Matthew Maurer7ae0b872019-09-05 14:14:26 -070021 | ------ borrow of `s` occurs here
Inna Palantff3f07a2019-07-11 16:15:26 -070022...
23LL | f[s] = 10;
24 | ^ move out of `s` occurs here
Matthew Maurer7ae0b872019-09-05 14:14:26 -070025...
26LL | use_mut(rs);
27 | -- borrow later used here
Inna Palantff3f07a2019-07-11 16:15:26 -070028
29error[E0382]: use of moved value: `s`
30 --> $DIR/borrowck-overloaded-index-move-index.rs:53:7
31 |
Matthew Maurer7ae0b872019-09-05 14:14:26 -070032LL | let mut s = "hello".to_string();
ThiƩbaud Weksteen3b664ca2020-11-26 14:41:59 +010033 | ----- move occurs because `s` has type `String`, which does not implement the `Copy` trait
Matthew Maurer7ae0b872019-09-05 14:14:26 -070034...
Inna Palantff3f07a2019-07-11 16:15:26 -070035LL | println!("{}", f[s]);
36 | - value moved here
37...
38LL | f[s] = 10;
39 | ^ value used here after move
Chris Wailes977026a2023-02-13 09:13:10 -080040 |
41help: consider cloning the value if the performance cost is acceptable
42 |
43LL | println!("{}", f[s.clone()]);
44 | ++++++++
Inna Palantff3f07a2019-07-11 16:15:26 -070045
46error: aborting due to 3 previous errors
47
Matthew Maurer7ae0b872019-09-05 14:14:26 -070048Some errors have detailed explanations: E0382, E0505.
Inna Palantff3f07a2019-07-11 16:15:26 -070049For more information about an error, try `rustc --explain E0382`.