@@ -23,7 +23,7 @@ use stdx::never;
23
23
use crate :: {
24
24
db:: { HirDatabase , InternedClosure } ,
25
25
from_placeholder_idx, make_binders,
26
- mir:: { BorrowKind , MirSpan , ProjectionElem } ,
26
+ mir:: { BorrowKind , MirSpan , MutBorrowKind , ProjectionElem } ,
27
27
static_lifetime, to_chalk_trait_id,
28
28
traits:: FnTrait ,
29
29
utils:: { self , generics, Generics } ,
@@ -142,9 +142,13 @@ impl HirPlace {
142
142
mut current_capture : CaptureKind ,
143
143
len : usize ,
144
144
) -> 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
+ {
146
149
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 } ) ;
148
152
}
149
153
}
150
154
current_capture
@@ -377,7 +381,7 @@ impl InferenceContext<'_> {
377
381
if let Some ( place) = self . place_of_expr ( expr) {
378
382
self . add_capture (
379
383
place,
380
- CaptureKind :: ByRef ( BorrowKind :: Mut { allow_two_phase_borrow : false } ) ,
384
+ CaptureKind :: ByRef ( BorrowKind :: Mut { kind : MutBorrowKind :: Default } ) ,
381
385
expr. into ( ) ,
382
386
) ;
383
387
}
@@ -426,9 +430,7 @@ impl InferenceContext<'_> {
426
430
427
431
fn ref_capture_with_adjusts ( & mut self , m : Mutability , tgt_expr : ExprId , rest : & [ Adjustment ] ) {
428
432
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 } ) ,
432
434
Mutability :: Not => CaptureKind :: ByRef ( BorrowKind :: Shared ) ,
433
435
} ;
434
436
if let Some ( place) = self . place_of_expr_without_adjust ( tgt_expr) {
@@ -648,7 +650,7 @@ impl InferenceContext<'_> {
648
650
self . walk_pat_inner (
649
651
pat,
650
652
& mut update_result,
651
- BorrowKind :: Mut { allow_two_phase_borrow : false } ,
653
+ BorrowKind :: Mut { kind : MutBorrowKind :: Default } ,
652
654
) ;
653
655
}
654
656
@@ -699,7 +701,7 @@ impl InferenceContext<'_> {
699
701
} ,
700
702
}
701
703
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 } ;
703
705
}
704
706
self . body . walk_pats_shallow ( p, |p| self . walk_pat_inner ( p, update_result, for_mut) ) ;
705
707
}
@@ -880,7 +882,7 @@ impl InferenceContext<'_> {
880
882
}
881
883
BindingMode :: Ref ( Mutability :: Not ) => BorrowKind :: Shared ,
882
884
BindingMode :: Ref ( Mutability :: Mut ) => {
883
- BorrowKind :: Mut { allow_two_phase_borrow : false }
885
+ BorrowKind :: Mut { kind : MutBorrowKind :: Default }
884
886
}
885
887
} ;
886
888
self . add_capture ( place, CaptureKind :: ByRef ( capture_kind) , pat. into ( ) ) ;
@@ -930,9 +932,7 @@ impl InferenceContext<'_> {
930
932
r = cmp:: min (
931
933
r,
932
934
match & it. kind {
933
- CaptureKind :: ByRef ( BorrowKind :: Unique | BorrowKind :: Mut { .. } ) => {
934
- FnTrait :: FnMut
935
- }
935
+ CaptureKind :: ByRef ( BorrowKind :: Mut { .. } ) => FnTrait :: FnMut ,
936
936
CaptureKind :: ByRef ( BorrowKind :: Shallow | BorrowKind :: Shared ) => FnTrait :: Fn ,
937
937
CaptureKind :: ByValue => FnTrait :: FnOnce ,
938
938
} ,
@@ -949,8 +949,12 @@ impl InferenceContext<'_> {
949
949
} ;
950
950
self . consume_expr ( * body) ;
951
951
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 )
954
958
{
955
959
// FIXME: remove the `mutated_bindings_in_closure` completely and add proper fake reads in
956
960
// MIR. I didn't do that due duplicate diagnostics.
0 commit comments