- match loan_path.kind {
- LpVar(local_id) |
- LpUpvar(ty::UpvarId{ var_id: local_id, closure_expr_id: _ }) => {
- self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
- }
- LpDowncast(ref base, _) |
- LpExtend(ref base, mc::McInherited, _) |
- LpExtend(ref base, mc::McDeclared, _) => {
- self.mark_loan_path_as_mutated(&base);
- }
- LpExtend(_, mc::McImmutable, _) => {
- // Nothing to do.
+ let mut wrapped_path = Some(loan_path);
+ let mut through_borrow = false;
+
+ while let Some(current_path) = wrapped_path {
+ wrapped_path = match current_path.kind {
+ LpVar(local_id) => {
+ if !through_borrow {
+ self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
+ }
+ None
+ }
+ LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
+ let local_id = self.tcx().hir.def_index_to_node_id(var_id);
+ self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
+ None
+ }
+ LpExtend(ref base, mc::McInherited, LpDeref(pointer_kind)) |
+ LpExtend(ref base, mc::McDeclared, LpDeref(pointer_kind)) => {
+ if pointer_kind != mc::Unique {
+ through_borrow = true;
+ }
+ Some(base)
+ }
+ LpDowncast(ref base, _) |
+ LpExtend(ref base, mc::McInherited, _) |
+ LpExtend(ref base, mc::McDeclared, _) => {
+ Some(base)
+ }
+ LpExtend(_, mc::McImmutable, _) => {
+ // Nothing to do.
+ None
+ }