@@ -727,7 +727,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
727727 let typeck_results = self . cx . typeck_results ( ) ;
728728 let adjustments = typeck_results. expr_adjustments ( expr) ;
729729 let mut place_with_id = self . cat_expr_unadjusted ( expr) ?;
730- for adjustment in adjustments {
730+ for ( adjustment_index, adjustment) in adjustments. iter ( ) . enumerate ( ) {
731+ let is_last_adjustment = adjustment_index + 1 == adjustments. len ( ) ;
731732 debug ! ( "walk_adjustment expr={:?} adj={:?}" , expr, adjustment) ;
732733 match adjustment. kind {
733734 adjustment:: Adjust :: NeverToAny | adjustment:: Adjust :: Pointer ( _) => {
@@ -752,13 +753,13 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
752753 self . walk_autoref ( expr, & place_with_id, autoref) ;
753754 }
754755
755- adjustment:: Adjust :: GenericReborrow ( _reborrow ) => {
756- // To build an expression as a place expression, it needs to be a field
757- // projection or deref at the outmost layer. So it is field projection or deref
758- // on an adjusted value. But this means that adjustment is applied on a
759- // subexpression that is not the final operand/rvalue for function call or
760- // assignment. This is a contradiction.
761- unreachable ! ( "Reborrow trait usage during adjustment walk ") ;
756+ adjustment:: Adjust :: GenericReborrow ( mutability ) if is_last_adjustment => {
757+ let bk = ty :: BorrowKind :: from_mutbl ( mutability ) ;
758+ self . delegate . borrow_mut ( ) . borrow ( & place_with_id , place_with_id . hir_id , bk ) ;
759+ }
760+
761+ adjustment :: Adjust :: GenericReborrow ( _ ) => {
762+ span_bug ! ( expr . span , "generic reborrow adjustment must be terminal ") ;
762763 }
763764 }
764765 place_with_id = self . cat_expr_adjusted ( expr, place_with_id, adjustment) ?;
0 commit comments