]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/index-mut-help.stderr
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / index-mut-help.stderr
1 error[E0596]: cannot borrow data in an index of `HashMap<&str, String>` as mutable
2   --> $DIR/index-mut-help.rs:10:5
3    |
4 LL |     map["peter"].clear();
5    |     ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
6    |
7    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
8 help: to modify a `HashMap<&str, String>` use `.get_mut()`
9    |
10 LL |     map.get_mut("peter").map(|val| val.clear());
11    |        ~~~~~~~~~       ~~~~~~~~~~~~~~~        +
12
13 error[E0594]: cannot assign to data in an index of `HashMap<&str, String>`
14   --> $DIR/index-mut-help.rs:11:5
15    |
16 LL |     map["peter"] = "0".to_string();
17    |     ^^^^^^^^^^^^ cannot assign
18    |
19    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
20 help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
21    |
22 LL |     map.insert("peter", "0".to_string());
23    |        ~~~~~~~~       ~                +
24 LL |     map.get_mut("peter").map(|val| { *val = "0".to_string(); });
25    |        ~~~~~~~~~       ~~~~~~~~~~~~~~~~~~                  ++++
26 LL |     let val = map.entry("peter").or_insert("0".to_string());
27    |     +++++++++    ~~~~~~~       ~~~~~~~~~~~~               +
28
29 error[E0596]: cannot borrow data in an index of `HashMap<&str, String>` as mutable
30   --> $DIR/index-mut-help.rs:12:13
31    |
32 LL |     let _ = &mut map["peter"];
33    |             ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
34    |
35    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
36    = help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
37
38 error: aborting due to 3 previous errors
39
40 Some errors have detailed explanations: E0594, E0596.
41 For more information about an error, try `rustc --explain E0594`.