@@ -324,6 +324,18 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
324324 }
325325 }
326326
327+ pub fn consume_clone_or_copy ( & self , place_with_id : & PlaceWithHirId < ' tcx > , diag_expr_id : HirId ) {
328+ debug ! ( "delegate_consume_or_clone(place_with_id={:?})" , place_with_id) ;
329+
330+ if self . cx . type_is_copy_modulo_regions ( place_with_id. place . ty ( ) ) {
331+ self . delegate . borrow_mut ( ) . copy ( place_with_id, diag_expr_id) ;
332+ } else if self . cx . type_is_use_cloned_modulo_regions ( place_with_id. place . ty ( ) ) {
333+ self . delegate . borrow_mut ( ) . use_cloned ( place_with_id, diag_expr_id) ;
334+ } else {
335+ self . delegate . borrow_mut ( ) . consume ( place_with_id, diag_expr_id) ;
336+ }
337+ }
338+
327339 fn consume_exprs ( & self , exprs : & [ hir:: Expr < ' _ > ] ) -> Result < ( ) , Cx :: Error > {
328340 for expr in exprs {
329341 self . consume_expr ( expr) ?;
@@ -346,15 +358,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
346358 debug ! ( "consume_or_clone_expr(expr={:?})" , expr) ;
347359
348360 let place_with_id = self . cat_expr ( expr) ?;
349-
350- if self . cx . type_is_copy_modulo_regions ( place_with_id. place . ty ( ) ) {
351- self . delegate . borrow_mut ( ) . copy ( & place_with_id, place_with_id. hir_id ) ;
352- } else if self . cx . type_is_use_cloned_modulo_regions ( place_with_id. place . ty ( ) ) {
353- self . delegate . borrow_mut ( ) . use_cloned ( & place_with_id, place_with_id. hir_id ) ;
354- } else {
355- self . delegate . borrow_mut ( ) . consume ( & place_with_id, place_with_id. hir_id ) ;
356- }
357-
361+ self . consume_clone_or_copy ( & place_with_id, place_with_id. hir_id ) ;
358362 self . walk_expr ( expr) ?;
359363 Ok ( ( ) )
360364 }
@@ -1132,9 +1136,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11321136 ) ;
11331137
11341138 match capture_info. capture_kind {
1135- ty:: UpvarCapture :: ByValue | ty :: UpvarCapture :: ByUse => {
1139+ ty:: UpvarCapture :: ByValue => {
11361140 self . consume_or_copy ( & place_with_id, place_with_id. hir_id ) ;
11371141 }
1142+ ty:: UpvarCapture :: ByUse => {
1143+ self . consume_clone_or_copy ( & place_with_id, place_with_id. hir_id ) ;
1144+ }
11381145 ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
11391146 self . delegate . borrow_mut ( ) . borrow (
11401147 & place_with_id,
0 commit comments