@@ -144,7 +144,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
144144 debug ! ( "delegate_consume(place_with_id={:?})" , place_with_id) ;
145145
146146 let mode = copy_or_move ( & self . mc , place_with_id) ;
147- self . delegate . consume ( place_with_id, diag_expr_id, mode) ;
147+
148+ match mode {
149+ ConsumeMode :: Move => self . delegate . consume ( place_with_id, diag_expr_id, mode) ,
150+ ConsumeMode :: Copy => {
151+ self . delegate . borrow ( place_with_id, diag_expr_id, ty:: BorrowKind :: ImmBorrow )
152+ }
153+ }
148154 }
149155
150156 fn consume_exprs ( & mut self , exprs : & [ hir:: Expr < ' _ > ] ) {
@@ -653,9 +659,18 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
653659 delegate. borrow( place, discr_place. hir_id, bk) ;
654660 }
655661 ty:: BindByValue ( ..) => {
656- let mode = copy_or_move( mc, & place) ;
657662 debug!( "walk_pat binding consuming pat" ) ;
658- delegate. consume( place, discr_place. hir_id, mode) ;
663+ let mode = copy_or_move( mc, & place) ;
664+ match mode {
665+ ConsumeMode :: Move => {
666+ delegate. consume( place, discr_place. hir_id, mode)
667+ }
668+ ConsumeMode :: Copy => delegate. borrow(
669+ place,
670+ discr_place. hir_id,
671+ ty:: BorrowKind :: ImmBorrow ,
672+ ) ,
673+ }
659674 }
660675 }
661676 }
@@ -773,8 +788,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
773788
774789 match capture_info. capture_kind {
775790 ty:: UpvarCapture :: ByValue ( _) => {
776- let mode = copy_or_move ( & self . mc , & place_with_id) ;
777- self . delegate . consume ( & place_with_id, place_with_id. hir_id , mode) ;
791+ self . delegate_consume ( & place_with_id, place_with_id. hir_id ) ;
778792 }
779793 ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
780794 self . delegate . borrow (
0 commit comments