@@ -751,7 +751,15 @@ fn constrain_callee(rcx: &mut Rcx,
751
751
ty:: ty_bare_fn( ..) => { }
752
752
ty:: ty_closure( ref closure_ty) => {
753
753
let region = match closure_ty. store {
754
- ty:: RegionTraitStore ( r, _) => r,
754
+ ty:: RegionTraitStore ( r, _) => {
755
+ // While we're here, link the closure's region with a unique
756
+ // immutable borrow (gathered later in borrowck)
757
+ let mc = mc:: MemCategorizationContext { typer : & * rcx } ;
758
+ let expr_cmt = ignore_err ! ( mc. cat_expr( callee_expr) ) ;
759
+ link_region ( mc. typer , callee_expr. span , call_region,
760
+ ty:: UniqueImmBorrow , expr_cmt) ;
761
+ r
762
+ }
755
763
ty:: UniqTraitStore => ty:: ReStatic
756
764
} ;
757
765
rcx. fcx . mk_subr ( true , infer:: InvokeClosure ( callee_expr. span ) ,
@@ -874,7 +882,8 @@ fn constrain_autoderefs(rcx: &mut Rcx,
874
882
{
875
883
let mc = mc:: MemCategorizationContext { typer : & * rcx } ;
876
884
let self_cmt = ignore_err ! ( mc. cat_expr_autoderefd( deref_expr, i) ) ;
877
- link_region ( mc. typer , deref_expr. span , r, m, self_cmt) ;
885
+ link_region ( mc. typer , deref_expr. span , r,
886
+ ty:: BorrowKind :: from_mutbl ( m) , self_cmt) ;
878
887
}
879
888
880
889
// Specialized version of constrain_call.
@@ -1092,7 +1101,8 @@ fn link_pattern(mc: mc::MemCategorizationContext<&Rcx>,
1092
1101
match mc. cat_slice_pattern ( sub_cmt, slice_pat) {
1093
1102
Ok ( ( slice_cmt, slice_mutbl, slice_r) ) => {
1094
1103
link_region ( mc. typer , sub_pat. span , slice_r,
1095
- slice_mutbl, slice_cmt) ;
1104
+ ty:: BorrowKind :: from_mutbl ( slice_mutbl) ,
1105
+ slice_cmt) ;
1096
1106
}
1097
1107
Err ( ( ) ) => { }
1098
1108
}
@@ -1118,17 +1128,20 @@ fn link_autoref(rcx: &Rcx,
1118
1128
1119
1129
match * autoref {
1120
1130
ty:: AutoPtr ( r, m) => {
1121
- link_region ( mc. typer , expr. span , r, m, expr_cmt) ;
1131
+ link_region ( mc. typer , expr. span , r,
1132
+ ty:: BorrowKind :: from_mutbl ( m) , expr_cmt) ;
1122
1133
}
1123
1134
1124
1135
ty:: AutoBorrowVec ( r, m) | ty:: AutoBorrowVecRef ( r, m) => {
1125
1136
let cmt_index = mc. cat_index ( expr, expr_cmt, autoderefs+1 ) ;
1126
- link_region ( mc. typer , expr. span , r, m, cmt_index) ;
1137
+ link_region ( mc. typer , expr. span , r,
1138
+ ty:: BorrowKind :: from_mutbl ( m) , cmt_index) ;
1127
1139
}
1128
1140
1129
1141
ty:: AutoBorrowObj ( r, m) => {
1130
1142
let cmt_deref = mc. cat_deref_obj ( expr, expr_cmt) ;
1131
- link_region ( mc. typer , expr. span , r, m, cmt_deref) ;
1143
+ link_region ( mc. typer , expr. span , r,
1144
+ ty:: BorrowKind :: from_mutbl ( m) , cmt_deref) ;
1132
1145
}
1133
1146
1134
1147
ty:: AutoUnsafe ( _) => { }
@@ -1150,7 +1163,7 @@ fn link_by_ref(rcx: &Rcx,
1150
1163
let mc = mc:: MemCategorizationContext { typer : rcx } ;
1151
1164
let expr_cmt = ignore_err ! ( mc. cat_expr( expr) ) ;
1152
1165
let region_min = ty:: ReScope ( callee_scope) ;
1153
- link_region ( mc. typer , expr. span , region_min, ast :: MutImmutable , expr_cmt) ;
1166
+ link_region ( mc. typer , expr. span , region_min, ty :: ImmBorrow , expr_cmt) ;
1154
1167
}
1155
1168
1156
1169
fn link_region_from_node_type ( rcx : & Rcx ,
@@ -1169,18 +1182,19 @@ fn link_region_from_node_type(rcx: &Rcx,
1169
1182
let tcx = rcx. fcx . ccx . tcx ;
1170
1183
debug ! ( "rptr_ty={}" , ty_to_str( tcx, rptr_ty) ) ;
1171
1184
let r = ty:: ty_region ( tcx, span, rptr_ty) ;
1172
- link_region ( rcx, span, r, mutbl, cmt_borrowed) ;
1185
+ link_region ( rcx, span, r, ty:: BorrowKind :: from_mutbl ( mutbl) ,
1186
+ cmt_borrowed) ;
1173
1187
}
1174
1188
}
1175
1189
1176
1190
fn link_region ( rcx : & Rcx ,
1177
1191
span : Span ,
1178
1192
region_min : ty:: Region ,
1179
- mutbl : ast :: Mutability ,
1193
+ kind : ty :: BorrowKind ,
1180
1194
cmt_borrowed : mc:: cmt ) {
1181
1195
/*!
1182
1196
* Informs the inference engine that a borrow of `cmt`
1183
- * must have mutability `mutbl ` and lifetime `region_min`.
1197
+ * must have the borrow kind `kind ` and lifetime `region_min`.
1184
1198
* If `cmt` is a deref of a region pointer with
1185
1199
* lifetime `r_borrowed`, this will add the constraint that
1186
1200
* `region_min <= r_borrowed`.
@@ -1190,9 +1204,9 @@ fn link_region(rcx: &Rcx,
1190
1204
// for the lifetime `region_min` for the borrow to be valid:
1191
1205
let mut cmt_borrowed = cmt_borrowed;
1192
1206
loop {
1193
- debug ! ( "link_region(region_min={}, mutbl ={}, cmt_borrowed={})" ,
1207
+ debug ! ( "link_region(region_min={}, kind ={}, cmt_borrowed={})" ,
1194
1208
region_min. repr( rcx. tcx( ) ) ,
1195
- mutbl . repr( rcx. tcx( ) ) ,
1209
+ kind . repr( rcx. tcx( ) ) ,
1196
1210
cmt_borrowed. repr( rcx. tcx( ) ) ) ;
1197
1211
match cmt_borrowed. cat . clone ( ) {
1198
1212
mc:: cat_deref( base, _, mc:: BorrowedPtr ( _, r_borrowed) ) => {
@@ -1214,7 +1228,7 @@ fn link_region(rcx: &Rcx,
1214
1228
adjust_upvar_borrow_kind_for_loan (
1215
1229
* upvar_id,
1216
1230
upvar_borrow,
1217
- mutbl ) ;
1231
+ kind ) ;
1218
1232
infer:: ReborrowUpvar ( span, * upvar_id)
1219
1233
}
1220
1234
None => {
@@ -1236,7 +1250,7 @@ fn link_region(rcx: &Rcx,
1236
1250
r_borrowed. repr( rcx. tcx( ) ) ) ;
1237
1251
rcx. fcx . mk_subr ( true , cause, region_min, r_borrowed) ;
1238
1252
1239
- if mutbl == ast :: MutMutable {
1253
+ if kind != ty :: ImmBorrow {
1240
1254
// If this is a mutable borrow, then the thing
1241
1255
// being borrowed will have to be unique.
1242
1256
// In user code, this means it must be an `&mut`
@@ -1428,12 +1442,11 @@ fn link_upvar_borrow_kind_for_nested_closures(rcx: &mut Rcx,
1428
1442
1429
1443
fn adjust_upvar_borrow_kind_for_loan ( upvar_id : ty:: UpvarId ,
1430
1444
upvar_borrow : & mut ty:: UpvarBorrow ,
1431
- mutbl : ast :: Mutability ) {
1445
+ kind : ty :: BorrowKind ) {
1432
1446
debug ! ( "adjust_upvar_borrow_kind_for_loan: upvar_id={:?} kind={:?} -> {:?}" ,
1433
- upvar_id, upvar_borrow. kind, mutbl ) ;
1447
+ upvar_id, upvar_borrow. kind, kind ) ;
1434
1448
1435
- adjust_upvar_borrow_kind ( upvar_id, upvar_borrow,
1436
- ty:: BorrowKind :: from_mutbl ( mutbl) )
1449
+ adjust_upvar_borrow_kind ( upvar_id, upvar_borrow, kind)
1437
1450
}
1438
1451
1439
1452
fn adjust_upvar_borrow_kind ( upvar_id : ty:: UpvarId ,
0 commit comments