@@ -23,7 +23,7 @@ use stdx::never;
2323use crate :: {
2424 db:: { HirDatabase , InternedClosure } ,
2525 from_placeholder_idx, make_binders,
26- mir:: { BorrowKind , MirSpan , ProjectionElem } ,
26+ mir:: { BorrowKind , MirSpan , MutBorrowKind , ProjectionElem } ,
2727 static_lifetime, to_chalk_trait_id,
2828 traits:: FnTrait ,
2929 utils:: { self , generics, Generics } ,
@@ -142,9 +142,13 @@ impl HirPlace {
142142 mut current_capture : CaptureKind ,
143143 len : usize ,
144144 ) -> CaptureKind {
145- if let CaptureKind :: ByRef ( BorrowKind :: Mut { .. } ) = current_capture {
145+ if let CaptureKind :: ByRef ( BorrowKind :: Mut {
146+ kind : MutBorrowKind :: Default | MutBorrowKind :: TwoPhasedBorrow ,
147+ } ) = current_capture
148+ {
146149 if self . projections [ len..] . iter ( ) . any ( |it| * it == ProjectionElem :: Deref ) {
147- current_capture = CaptureKind :: ByRef ( BorrowKind :: Unique ) ;
150+ current_capture =
151+ CaptureKind :: ByRef ( BorrowKind :: Mut { kind : MutBorrowKind :: ClosureCapture } ) ;
148152 }
149153 }
150154 current_capture
@@ -377,7 +381,7 @@ impl InferenceContext<'_> {
377381 if let Some ( place) = self . place_of_expr ( expr) {
378382 self . add_capture (
379383 place,
380- CaptureKind :: ByRef ( BorrowKind :: Mut { allow_two_phase_borrow : false } ) ,
384+ CaptureKind :: ByRef ( BorrowKind :: Mut { kind : MutBorrowKind :: Default } ) ,
381385 expr. into ( ) ,
382386 ) ;
383387 }
@@ -426,9 +430,7 @@ impl InferenceContext<'_> {
426430
427431 fn ref_capture_with_adjusts ( & mut self , m : Mutability , tgt_expr : ExprId , rest : & [ Adjustment ] ) {
428432 let capture_kind = match m {
429- Mutability :: Mut => {
430- CaptureKind :: ByRef ( BorrowKind :: Mut { allow_two_phase_borrow : false } )
431- }
433+ Mutability :: Mut => CaptureKind :: ByRef ( BorrowKind :: Mut { kind : MutBorrowKind :: Default } ) ,
432434 Mutability :: Not => CaptureKind :: ByRef ( BorrowKind :: Shared ) ,
433435 } ;
434436 if let Some ( place) = self . place_of_expr_without_adjust ( tgt_expr) {
@@ -648,7 +650,7 @@ impl InferenceContext<'_> {
648650 self . walk_pat_inner (
649651 pat,
650652 & mut update_result,
651- BorrowKind :: Mut { allow_two_phase_borrow : false } ,
653+ BorrowKind :: Mut { kind : MutBorrowKind :: Default } ,
652654 ) ;
653655 }
654656
@@ -699,7 +701,7 @@ impl InferenceContext<'_> {
699701 } ,
700702 }
701703 if self . result . pat_adjustments . get ( & p) . map_or ( false , |it| !it. is_empty ( ) ) {
702- for_mut = BorrowKind :: Unique ;
704+ for_mut = BorrowKind :: Mut { kind : MutBorrowKind :: ClosureCapture } ;
703705 }
704706 self . body . walk_pats_shallow ( p, |p| self . walk_pat_inner ( p, update_result, for_mut) ) ;
705707 }
@@ -880,7 +882,7 @@ impl InferenceContext<'_> {
880882 }
881883 BindingMode :: Ref ( Mutability :: Not ) => BorrowKind :: Shared ,
882884 BindingMode :: Ref ( Mutability :: Mut ) => {
883- BorrowKind :: Mut { allow_two_phase_borrow : false }
885+ BorrowKind :: Mut { kind : MutBorrowKind :: Default }
884886 }
885887 } ;
886888 self . add_capture ( place, CaptureKind :: ByRef ( capture_kind) , pat. into ( ) ) ;
@@ -930,9 +932,7 @@ impl InferenceContext<'_> {
930932 r = cmp:: min (
931933 r,
932934 match & it. kind {
933- CaptureKind :: ByRef ( BorrowKind :: Unique | BorrowKind :: Mut { .. } ) => {
934- FnTrait :: FnMut
935- }
935+ CaptureKind :: ByRef ( BorrowKind :: Mut { .. } ) => FnTrait :: FnMut ,
936936 CaptureKind :: ByRef ( BorrowKind :: Shallow | BorrowKind :: Shared ) => FnTrait :: Fn ,
937937 CaptureKind :: ByValue => FnTrait :: FnOnce ,
938938 } ,
@@ -949,8 +949,12 @@ impl InferenceContext<'_> {
949949 } ;
950950 self . consume_expr ( * body) ;
951951 for item in & self . current_captures {
952- if matches ! ( item. kind, CaptureKind :: ByRef ( BorrowKind :: Mut { .. } ) )
953- && !item. place . projections . contains ( & ProjectionElem :: Deref )
952+ if matches ! (
953+ item. kind,
954+ CaptureKind :: ByRef ( BorrowKind :: Mut {
955+ kind: MutBorrowKind :: Default | MutBorrowKind :: TwoPhasedBorrow
956+ } )
957+ ) && !item. place . projections . contains ( & ProjectionElem :: Deref )
954958 {
955959 // FIXME: remove the `mutated_bindings_in_closure` completely and add proper fake reads in
956960 // MIR. I didn't do that due duplicate diagnostics.
0 commit comments