@@ -74,7 +74,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
74
74
75
75
struct SeedBorrowKind < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
76
76
fcx : & ' a FnCtxt < ' a , ' gcx , ' tcx > ,
77
- temp_closure_kinds : NodeMap < ty:: ClosureKind > ,
77
+ temp_closure_kinds : NodeMap < ( ty:: ClosureKind , Option < Span > ) > ,
78
78
}
79
79
80
80
impl < ' a , ' gcx , ' tcx > Visitor < ' gcx > for SeedBorrowKind < ' a , ' gcx , ' tcx > {
@@ -107,7 +107,7 @@ impl<'a, 'gcx, 'tcx> SeedBorrowKind<'a, 'gcx, 'tcx> {
107
107
capture_clause : hir:: CaptureClause )
108
108
{
109
109
if !self . fcx . tables . borrow ( ) . closure_kinds . contains_key ( & expr. id ) {
110
- self . temp_closure_kinds . insert ( expr. id , ty:: ClosureKind :: Fn ) ;
110
+ self . temp_closure_kinds . insert ( expr. id , ( ty:: ClosureKind :: Fn , None ) ) ;
111
111
debug ! ( "check_closure: adding closure {:?} as Fn" , expr. id) ;
112
112
}
113
113
@@ -143,12 +143,12 @@ impl<'a, 'gcx, 'tcx> SeedBorrowKind<'a, 'gcx, 'tcx> {
143
143
144
144
struct AdjustBorrowKind < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
145
145
fcx : & ' a FnCtxt < ' a , ' gcx , ' tcx > ,
146
- temp_closure_kinds : NodeMap < ty:: ClosureKind > ,
146
+ temp_closure_kinds : NodeMap < ( ty:: ClosureKind , Option < Span > ) > ,
147
147
}
148
148
149
149
impl < ' a , ' gcx , ' tcx > AdjustBorrowKind < ' a , ' gcx , ' tcx > {
150
150
fn new ( fcx : & ' a FnCtxt < ' a , ' gcx , ' tcx > ,
151
- temp_closure_kinds : NodeMap < ty:: ClosureKind > )
151
+ temp_closure_kinds : NodeMap < ( ty:: ClosureKind , Option < Span > ) > )
152
152
-> AdjustBorrowKind < ' a , ' gcx , ' tcx > {
153
153
AdjustBorrowKind { fcx : fcx, temp_closure_kinds : temp_closure_kinds }
154
154
}
@@ -211,8 +211,8 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
211
211
212
212
// If we are also inferred the closure kind here, update the
213
213
// main table and process any deferred resolutions.
214
- if let Some ( & kind) = self . temp_closure_kinds . get ( & id) {
215
- self . fcx . tables . borrow_mut ( ) . closure_kinds . insert ( id, kind) ;
214
+ if let Some ( & ( kind, span ) ) = self . temp_closure_kinds . get ( & id) {
215
+ self . fcx . tables . borrow_mut ( ) . closure_kinds . insert ( id, ( kind, span ) ) ;
216
216
let closure_def_id = self . fcx . tcx . hir . local_def_id ( id) ;
217
217
debug ! ( "closure_kind({:?}) = {:?}" , closure_def_id, kind) ;
218
218
@@ -276,6 +276,7 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
276
276
// for that to be legal, the upvar would have to be borrowed
277
277
// by value instead
278
278
let guarantor = cmt. guarantor ( ) ;
279
+ let tcx = self . fcx . tcx ;
279
280
debug ! ( "adjust_upvar_borrow_kind_for_consume: guarantor={:?}" ,
280
281
guarantor) ;
281
282
match guarantor. cat {
@@ -289,7 +290,8 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
289
290
290
291
// to move out of an upvar, this must be a FnOnce closure
291
292
self . adjust_closure_kind ( upvar_id. closure_expr_id ,
292
- ty:: ClosureKind :: FnOnce ) ;
293
+ ty:: ClosureKind :: FnOnce ,
294
+ tcx. hir . span ( upvar_id. var_id ) ) ;
293
295
294
296
let upvar_capture_map =
295
297
& mut self . fcx . tables . borrow_mut ( ) . upvar_capture_map ;
@@ -303,7 +305,8 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
303
305
// to be a FnOnce closure to permit moves out
304
306
// of the environment.
305
307
self . adjust_closure_kind ( upvar_id. closure_expr_id ,
306
- ty:: ClosureKind :: FnOnce ) ;
308
+ ty:: ClosureKind :: FnOnce ,
309
+ tcx. hir . span ( upvar_id. var_id ) ) ;
307
310
}
308
311
mc:: NoteNone => {
309
312
}
@@ -394,6 +397,8 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
394
397
ty:: ImmBorrow => false ,
395
398
} ) ;
396
399
400
+ let tcx = self . fcx . tcx ;
401
+
397
402
match * note {
398
403
mc:: NoteUpvarRef ( upvar_id) => {
399
404
// if this is an implicit deref of an
@@ -407,15 +412,19 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
407
412
}
408
413
409
414
// also need to be in an FnMut closure since this is not an ImmBorrow
410
- self . adjust_closure_kind ( upvar_id. closure_expr_id , ty:: ClosureKind :: FnMut ) ;
415
+ self . adjust_closure_kind ( upvar_id. closure_expr_id ,
416
+ ty:: ClosureKind :: FnMut ,
417
+ tcx. hir . span ( upvar_id. var_id ) ) ;
411
418
412
419
true
413
420
}
414
421
mc:: NoteClosureEnv ( upvar_id) => {
415
422
// this kind of deref occurs in a `move` closure, or
416
423
// for a by-value upvar; in either case, to mutate an
417
424
// upvar, we need to be an FnMut closure
418
- self . adjust_closure_kind ( upvar_id. closure_expr_id , ty:: ClosureKind :: FnMut ) ;
425
+ self . adjust_closure_kind ( upvar_id. closure_expr_id ,
426
+ ty:: ClosureKind :: FnMut ,
427
+ tcx. hir . span ( upvar_id. var_id ) ) ;
419
428
420
429
true
421
430
}
@@ -462,11 +471,12 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
462
471
463
472
fn adjust_closure_kind ( & mut self ,
464
473
closure_id : ast:: NodeId ,
465
- new_kind : ty:: ClosureKind ) {
474
+ new_kind : ty:: ClosureKind ,
475
+ upvar_span : Span ) {
466
476
debug ! ( "adjust_closure_kind(closure_id={}, new_kind={:?})" ,
467
477
closure_id, new_kind) ;
468
478
469
- if let Some ( & existing_kind) = self . temp_closure_kinds . get ( & closure_id) {
479
+ if let Some ( & ( existing_kind, _ ) ) = self . temp_closure_kinds . get ( & closure_id) {
470
480
debug ! ( "adjust_closure_kind: closure_id={}, existing_kind={:?}, new_kind={:?}" ,
471
481
closure_id, existing_kind, new_kind) ;
472
482
@@ -482,7 +492,7 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
482
492
( ty:: ClosureKind :: Fn , ty:: ClosureKind :: FnOnce ) |
483
493
( ty:: ClosureKind :: FnMut , ty:: ClosureKind :: FnOnce ) => {
484
494
// new kind is stronger than the old kind
485
- self . temp_closure_kinds . insert ( closure_id, new_kind) ;
495
+ self . temp_closure_kinds . insert ( closure_id, ( new_kind, Some ( upvar_span ) ) ) ;
486
496
}
487
497
}
488
498
}
0 commit comments