@@ -176,6 +176,41 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
176
176
euv. walk_fn ( decl, body) ;
177
177
}
178
178
179
+ fn adjust_upvar_borrow_kind_for_consume ( & self ,
180
+ cmt : mc:: cmt < ' tcx > ,
181
+ mode : euv:: ConsumeMode )
182
+ {
183
+ debug ! ( "adjust_upvar_borrow_kind_for_consume(cmt={}, mode={:?})" ,
184
+ cmt. repr( self . tcx( ) ) , mode) ;
185
+
186
+ // we only care about moves
187
+ match mode {
188
+ euv:: Copy => { return ; }
189
+ euv:: Move ( _) => { }
190
+ }
191
+
192
+ // watch out for a move of the deref of a borrowed pointer;
193
+ // for that to be legal, the upvar would have to be borrowed
194
+ // by value instead
195
+ let guarantor = cmt. guarantor ( ) ;
196
+ debug ! ( "adjust_upvar_borrow_kind_for_consume: guarantor={}" ,
197
+ guarantor. repr( self . tcx( ) ) ) ;
198
+ match guarantor. cat {
199
+ mc:: cat_deref( _, _, mc:: BorrowedPtr ( ..) ) |
200
+ mc:: cat_deref( _, _, mc:: Implicit ( ..) ) => {
201
+ if let mc:: NoteUpvarRef ( upvar_id) = cmt. note {
202
+ debug ! ( "adjust_upvar_borrow_kind_for_consume: \
203
+ setting upvar_id={:?} to by value",
204
+ upvar_id) ;
205
+
206
+ let mut upvar_capture_map = self . fcx . inh . upvar_capture_map . borrow_mut ( ) ;
207
+ upvar_capture_map. insert ( upvar_id, ty:: UpvarCapture :: ByValue ) ;
208
+ }
209
+ }
210
+ _ => { }
211
+ }
212
+ }
213
+
179
214
/// Indicates that `cmt` is being directly mutated (e.g., assigned
180
215
/// to). If cmt contains any by-ref upvars, this implies that
181
216
/// those upvars must be borrowed using an `&mut` borow.
@@ -319,9 +354,12 @@ impl<'a,'tcx> euv::Delegate<'tcx> for AdjustBorrowKind<'a,'tcx> {
319
354
fn consume ( & mut self ,
320
355
_consume_id : ast:: NodeId ,
321
356
_consume_span : Span ,
322
- _cmt : mc:: cmt < ' tcx > ,
323
- _mode : euv:: ConsumeMode )
324
- { }
357
+ cmt : mc:: cmt < ' tcx > ,
358
+ mode : euv:: ConsumeMode )
359
+ {
360
+ debug ! ( "consume(cmt={},mode={:?})" , cmt. repr( self . tcx( ) ) , mode) ;
361
+ self . adjust_upvar_borrow_kind_for_consume ( cmt, mode) ;
362
+ }
325
363
326
364
fn matched_pat ( & mut self ,
327
365
_matched_pat : & ast:: Pat ,
@@ -331,9 +369,12 @@ impl<'a,'tcx> euv::Delegate<'tcx> for AdjustBorrowKind<'a,'tcx> {
331
369
332
370
fn consume_pat ( & mut self ,
333
371
_consume_pat : & ast:: Pat ,
334
- _cmt : mc:: cmt < ' tcx > ,
335
- _mode : euv:: ConsumeMode )
336
- { }
372
+ cmt : mc:: cmt < ' tcx > ,
373
+ mode : euv:: ConsumeMode )
374
+ {
375
+ debug ! ( "consume_pat(cmt={},mode={:?})" , cmt. repr( self . tcx( ) ) , mode) ;
376
+ self . adjust_upvar_borrow_kind_for_consume ( cmt, mode) ;
377
+ }
337
378
338
379
fn borrow ( & mut self ,
339
380
borrow_id : ast:: NodeId ,
0 commit comments