Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/closure.rs')
| -rw-r--r-- | crates/hir-ty/src/infer/closure.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index 7878ebcc58..787c5c54a2 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -643,7 +643,21 @@ impl InferenceContext<'_> { } None => *result = Some(ck), }; - self.body.walk_pats(pat, &mut |p| match &self.body[p] { + + self.walk_pat_inner( + pat, + &mut update_result, + BorrowKind::Mut { allow_two_phase_borrow: false }, + ); + } + + fn walk_pat_inner( + &mut self, + p: PatId, + update_result: &mut impl FnMut(CaptureKind), + mut for_mut: BorrowKind, + ) { + match &self.body[p] { Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing @@ -678,13 +692,15 @@ impl InferenceContext<'_> { } } crate::BindingMode::Ref(r) => match r { - Mutability::Mut => update_result(CaptureKind::ByRef(BorrowKind::Mut { - allow_two_phase_borrow: false, - })), + Mutability::Mut => update_result(CaptureKind::ByRef(for_mut)), Mutability::Not => update_result(CaptureKind::ByRef(BorrowKind::Shared)), }, }, - }); + } + if self.result.pat_adjustments.get(&p).map_or(false, |x| !x.is_empty()) { + for_mut = BorrowKind::Unique; + } + self.body.walk_pats_shallow(p, |p| self.walk_pat_inner(p, update_result, for_mut)); } fn expr_ty(&self, expr: ExprId) -> Ty { |