Fix span for IndexMut method call on HashMap/BTreeMap
This commit is contained in:
parent
6a3474e653
commit
f28e13b055
3 changed files with 10 additions and 4 deletions
|
@ -624,7 +624,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
self.suggested = true;
|
||||
} else if let hir::ExprKind::MethodCall(_path, receiver, _, sp) = expr.kind
|
||||
&& let hir::ExprKind::Index(val, index, _) = receiver.kind
|
||||
&& expr.span == self.assign_span
|
||||
&& receiver.span == self.assign_span
|
||||
{
|
||||
// val[index].path(args..);
|
||||
self.err.multipart_suggestion(
|
||||
|
@ -639,7 +639,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
index.span.shrink_to_hi().with_hi(receiver.span.hi()),
|
||||
") { val".to_string(),
|
||||
),
|
||||
(sp.shrink_to_hi(), "); }".to_string()),
|
||||
(sp.shrink_to_hi(), "; }".to_string()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
|
|
@ -5,7 +5,10 @@ LL | map["peter"].clear();
|
|||
| ^^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
|
||||
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
|
||||
= help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
|
||||
help: to modify a `HashMap<&str, String>` use `.get_mut()`
|
||||
|
|
||||
LL | if let Some(val) = map.get_mut("peter") { val.clear(); };
|
||||
| ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~ +++
|
||||
|
||||
error[E0594]: cannot assign to data in an index of `HashMap<&str, String>`
|
||||
--> $DIR/index-mut-help.rs:11:5
|
||||
|
|
|
@ -5,7 +5,10 @@ LL | things[src.as_str()].sort();
|
|||
| ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
|
||||
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<String, Vec<String>>`
|
||||
= help: to modify a `HashMap<String, Vec<String>>`, use `.get_mut()`, `.insert()` or the entry API
|
||||
help: to modify a `HashMap<String, Vec<String>>` use `.get_mut()`
|
||||
|
|
||||
LL | if let Some(val) = things.get_mut(src.as_str()) { val.sort(); };
|
||||
| ++++++++++++++++++ ~~~~~~~~~ ~~~~~~~ +++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue