@@ -1008,12 +1008,27 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1008
1008
Control :: Continue
1009
1009
}
1010
1010
1011
- ( Read ( _) , BorrowKind :: Shared ) | ( Reservation ( ..) , BorrowKind :: Shared )
1012
- | ( Read ( _) , BorrowKind :: Shallow ) | ( Reservation ( ..) , BorrowKind :: Shallow ) => {
1011
+ ( Read ( _) , BorrowKind :: Shared )
1012
+ | ( Read ( _) , BorrowKind :: Shallow )
1013
+ | ( Read ( _) , BorrowKind :: Guard ) => {
1013
1014
Control :: Continue
1014
1015
}
1015
1016
1016
- ( Write ( WriteKind :: Move ) , BorrowKind :: Shallow ) => {
1017
+ ( Reservation ( ..) , BorrowKind :: Shallow )
1018
+ | ( Reservation ( ..) , BorrowKind :: Guard ) => {
1019
+ // `Shallow` and `Guard` borrows only exist to prevent
1020
+ // mutation, which a `Reservation` is not, even though it
1021
+ // creates a mutable reference.
1022
+ //
1023
+ // We don't allow `Shared` borrows here, since it is
1024
+ // undecided whether the mutable reference that is
1025
+ // created by the `Reservation` should be unique when it's
1026
+ // created.
1027
+ Control :: Continue
1028
+ }
1029
+
1030
+ ( Write ( WriteKind :: Move ) , BorrowKind :: Shallow )
1031
+ | ( Write ( WriteKind :: Move ) , BorrowKind :: Guard ) => {
1017
1032
// Handled by initialization checks.
1018
1033
Control :: Continue
1019
1034
}
@@ -1037,7 +1052,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1037
1052
Control :: Break
1038
1053
}
1039
1054
1040
- ( Reservation ( kind) , BorrowKind :: Unique )
1055
+ ( Reservation ( kind) , BorrowKind :: Shared )
1056
+ | ( Reservation ( kind) , BorrowKind :: Unique )
1041
1057
| ( Reservation ( kind) , BorrowKind :: Mut { .. } )
1042
1058
| ( Activation ( kind, _) , _)
1043
1059
| ( Write ( kind) , _) => {
@@ -1149,7 +1165,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1149
1165
BorrowKind :: Shallow => {
1150
1166
( Shallow ( Some ( ArtificialField :: ShallowBorrow ) ) , Read ( ReadKind :: Borrow ( bk) ) )
1151
1167
} ,
1152
- BorrowKind :: Shared => ( Deep , Read ( ReadKind :: Borrow ( bk) ) ) ,
1168
+ BorrowKind :: Shared | BorrowKind :: Guard => ( Deep , Read ( ReadKind :: Borrow ( bk) ) ) ,
1153
1169
BorrowKind :: Unique | BorrowKind :: Mut { .. } => {
1154
1170
let wk = WriteKind :: MutableBorrow ( bk) ;
1155
1171
if allow_two_phase_borrow ( & self . infcx . tcx , bk) {
@@ -1168,10 +1184,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1168
1184
flow_state,
1169
1185
) ;
1170
1186
1171
- let action = if bk == BorrowKind :: Shallow {
1172
- InitializationRequiringAction :: MatchOn
1173
- } else {
1174
- InitializationRequiringAction :: Borrow
1187
+ let action = match bk {
1188
+ BorrowKind :: Shallow | BorrowKind :: Guard => {
1189
+ InitializationRequiringAction :: MatchOn
1190
+ }
1191
+ BorrowKind :: Shared | BorrowKind :: Unique | BorrowKind :: Mut { .. } => {
1192
+ InitializationRequiringAction :: Borrow
1193
+ }
1175
1194
} ;
1176
1195
1177
1196
self . check_if_path_or_subpath_is_moved (
@@ -1421,7 +1440,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1421
1440
1422
1441
// only mutable borrows should be 2-phase
1423
1442
assert ! ( match borrow. kind {
1424
- BorrowKind :: Shared | BorrowKind :: Shallow => false ,
1443
+ BorrowKind :: Shared | BorrowKind :: Shallow | BorrowKind :: Guard => false ,
1425
1444
BorrowKind :: Unique | BorrowKind :: Mut { .. } => true ,
1426
1445
} ) ;
1427
1446
@@ -1832,7 +1851,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1832
1851
let is_local_mutation_allowed = match borrow_kind {
1833
1852
BorrowKind :: Unique => LocalMutationIsAllowed :: Yes ,
1834
1853
BorrowKind :: Mut { .. } => is_local_mutation_allowed,
1835
- BorrowKind :: Shared | BorrowKind :: Shallow => unreachable ! ( ) ,
1854
+ BorrowKind :: Shared | BorrowKind :: Shallow | BorrowKind :: Guard => unreachable ! ( ) ,
1836
1855
} ;
1837
1856
match self . is_mutable ( place, is_local_mutation_allowed) {
1838
1857
Ok ( root_place) => {
@@ -1863,9 +1882,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1863
1882
| Reservation ( wk @ WriteKind :: StorageDeadOrDrop )
1864
1883
| Reservation ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shared ) )
1865
1884
| Reservation ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shallow ) )
1885
+ | Reservation ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Guard ) )
1866
1886
| Write ( wk @ WriteKind :: StorageDeadOrDrop )
1867
1887
| Write ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shared ) )
1868
- | Write ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shallow ) ) => {
1888
+ | Write ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shallow ) )
1889
+ | Write ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Guard ) ) => {
1869
1890
if let ( Err ( _place_err) , true ) = (
1870
1891
self . is_mutable ( place, is_local_mutation_allowed) ,
1871
1892
self . errors_buffer . is_empty ( )
@@ -1911,6 +1932,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1911
1932
| Read ( ReadKind :: Borrow ( BorrowKind :: Mut { .. } ) )
1912
1933
| Read ( ReadKind :: Borrow ( BorrowKind :: Shared ) )
1913
1934
| Read ( ReadKind :: Borrow ( BorrowKind :: Shallow ) )
1935
+ | Read ( ReadKind :: Borrow ( BorrowKind :: Guard ) )
1914
1936
| Read ( ReadKind :: Copy ) => {
1915
1937
// Access authorized
1916
1938
return false ;
0 commit comments