Skip to content

Commit b994124

Browse files
Explain how to mutate a HashMap/BTreeMap with more nuance
1 parent 7f75bfa commit b994124

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
575575
// ---------- place
576576
self.err.multipart_suggestions(
577577
format!(
578-
"to modify a `{}`, use `.get_mut()`, `.insert()` or the entry API",
578+
"use `.insert()` to insert a value into a `{}`, `.get_mut()` to modify it, or the entry API for more flexibility",
579579
self.ty,
580580
),
581581
vec![

tests/ui/borrowck/index-mut-help.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | map["peter"] = "0".to_string();
1414
| ^^^^^^^^^^^^ cannot assign
1515
|
1616
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
17-
help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
17+
help: use `.insert()` to insert a value into a `HashMap<&str, String>`, `.get_mut()` to modify it, or the entry API for more flexibility
1818
|
1919
LL | map.insert("peter", "0".to_string());
2020
| ~~~~~~~~ ~ +

tests/ui/btreemap/btreemap-index-mut-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | map[&0] = 1;
55
| ^^^^^^^^^^^ cannot assign
66
|
77
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `BTreeMap<u32, u32>`
8-
help: to modify a `BTreeMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API
8+
help: use `.insert()` to insert a value into a `BTreeMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility
99
|
1010
LL | map.insert(&0, 1);
1111
| ~~~~~~~~ ~ +

tests/ui/btreemap/btreemap-index-mut.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | map[&0] = 1;
55
| ^^^^^^^^^^^ cannot assign
66
|
77
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `BTreeMap<u32, u32>`
8-
help: to modify a `BTreeMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API
8+
help: use `.insert()` to insert a value into a `BTreeMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility
99
|
1010
LL | map.insert(&0, 1);
1111
| ~~~~~~~~ ~ +

tests/ui/hashmap/hashmap-index-mut.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | map[&0] = 1;
55
| ^^^^^^^^^^^ cannot assign
66
|
77
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<u32, u32>`
8-
help: to modify a `HashMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API
8+
help: use `.insert()` to insert a value into a `HashMap<u32, u32>`, `.get_mut()` to modify it, or the entry API for more flexibility
99
|
1010
LL | map.insert(&0, 1);
1111
| ~~~~~~~~ ~ +

0 commit comments

Comments
 (0)