Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | error[E0505]: cannot move out of `s` because it is borrowed |
| 2 | --> $DIR/borrowck-overloaded-index-move-index.rs:50:22 |
| 3 | | |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 4 | LL | let mut s = "hello".to_string(); |
| 5 | | ----- binding `s` declared here |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 6 | LL | let rs = &mut s; |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 7 | | ------ borrow of `s` occurs here |
Chris Wailes | 6572058 | 2022-08-11 09:53:28 -0700 | [diff] [blame] | 8 | LL | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 9 | LL | println!("{}", f[s]); |
| 10 | | ^ move out of `s` occurs here |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 11 | ... |
| 12 | LL | use_mut(rs); |
| 13 | | -- borrow later used here |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 14 | |
| 15 | error[E0505]: cannot move out of `s` because it is borrowed |
| 16 | --> $DIR/borrowck-overloaded-index-move-index.rs:53:7 |
| 17 | | |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 18 | LL | let mut s = "hello".to_string(); |
| 19 | | ----- binding `s` declared here |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 20 | LL | let rs = &mut s; |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 21 | | ------ borrow of `s` occurs here |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 22 | ... |
| 23 | LL | f[s] = 10; |
| 24 | | ^ move out of `s` occurs here |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 25 | ... |
| 26 | LL | use_mut(rs); |
| 27 | | -- borrow later used here |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 28 | |
| 29 | error[E0382]: use of moved value: `s` |
| 30 | --> $DIR/borrowck-overloaded-index-move-index.rs:53:7 |
| 31 | | |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 32 | LL | let mut s = "hello".to_string(); |
ThiƩbaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 33 | | ----- move occurs because `s` has type `String`, which does not implement the `Copy` trait |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 34 | ... |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 35 | LL | println!("{}", f[s]); |
| 36 | | - value moved here |
| 37 | ... |
| 38 | LL | f[s] = 10; |
| 39 | | ^ value used here after move |
Chris Wailes | 977026a | 2023-02-13 09:13:10 -0800 | [diff] [blame] | 40 | | |
| 41 | help: consider cloning the value if the performance cost is acceptable |
| 42 | | |
| 43 | LL | println!("{}", f[s.clone()]); |
| 44 | | ++++++++ |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 45 | |
| 46 | error: aborting due to 3 previous errors |
| 47 | |
Matthew Maurer | 7ae0b87 | 2019-09-05 14:14:26 -0700 | [diff] [blame] | 48 | Some errors have detailed explanations: E0382, E0505. |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 49 | For more information about an error, try `rustc --explain E0382`. |