+ let mut needs_mut = false;
+ let res = for_each_local_use_after_expr(cx, self.local_id, self.last_push_expr, |e| {
+ let Some(parent) = get_parent_expr(cx, e) else {
+ return ControlFlow::Continue(())
+ };
+ let adjusted_ty = cx.typeck_results().expr_ty_adjusted(e);
+ let adjusted_mut = adjusted_ty.ref_mutability().unwrap_or(Mutability::Not);
+ needs_mut |= adjusted_mut == Mutability::Mut;
+ match parent.kind {
+ ExprKind::AddrOf(_, Mutability::Mut, _) => {
+ needs_mut = true;
+ return ControlFlow::Break(true);
+ },
+ ExprKind::Unary(UnOp::Deref, _) | ExprKind::Index(..) if !needs_mut => {
+ let mut last_place = parent;
+ while let Some(parent) = get_parent_expr(cx, last_place) {
+ if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..))
+ || matches!(parent.kind, ExprKind::Index(e, _) if e.hir_id == last_place.hir_id)
+ {
+ last_place = parent;
+ } else {
+ break;
+ }
+ }
+ needs_mut |= cx.typeck_results().expr_ty_adjusted(last_place).ref_mutability()
+ == Some(Mutability::Mut)
+ || get_parent_expr(cx, last_place)
+ .map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _)));
+ },
+ ExprKind::MethodCall(_, recv, ..)
+ if recv.hir_id == e.hir_id
+ && adjusted_mut == Mutability::Mut
+ && !adjusted_ty.peel_refs().is_slice() =>
+ {
+ // No need to set `needs_mut` to true. The receiver will be either explicitly borrowed, or it will
+ // be implicitly borrowed via an adjustment. Both of these cases are already handled by this point.
+ return ControlFlow::Break(true);
+ },
+ ExprKind::Assign(lhs, ..) if e.hir_id == lhs.hir_id => {
+ needs_mut = true;
+ return ControlFlow::Break(false);
+ },
+ _ => (),
+ }
+ ControlFlow::Continue(())
+ });
+
+ // Avoid allocating small `Vec`s when they'll be extended right after.
+ if res == ControlFlow::Break(true) && self.found <= required_pushes_before_extension {
+ return;
+ }
+
+ let mut s = if self.lhs_is_let {