@@ -176,7 +176,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
176176 self . demand_eqtype ( span, inferred_kind. to_ty ( self . tcx ) , closure_kind_ty) ;
177177
178178 // If we have an origin, store it.
179- if let Some ( origin) = delegate. current_origin {
179+ if let Some ( origin) = delegate. current_origin . clone ( ) {
180+ let origin = if self . tcx . features ( ) . capture_disjoint_fields {
181+ origin
182+ } else {
183+ // FIXME(project-rfc-2229#26): Once rust-lang#80092 is merged, we should restrict the
184+ // precision of origin as well. Otherwise, this will cause issues when project-rfc-2229#26
185+ // is fixed as we might see Index projections in the origin, which we can't print because
186+ // we don't store enough information.
187+ ( origin. 0 , Place { projections : vec ! [ ] , ..origin. 1 } )
188+ } ;
189+
180190 self . typeck_results
181191 . borrow_mut ( )
182192 . closure_kind_origins_mut ( )
@@ -563,7 +573,7 @@ struct InferBorrowKind<'a, 'tcx> {
563573
564574 // If we modified `current_closure_kind`, this field contains a `Some()` with the
565575 // variable access that caused us to do so.
566- current_origin : Option < ( Span , Symbol ) > ,
576+ current_origin : Option < ( Span , Place < ' tcx > ) > ,
567577
568578 /// For each Place that is captured by the closure, we track the minimal kind of
569579 /// access we need (ref, ref mut, move, etc) and the expression that resulted in such access.
@@ -628,7 +638,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
628638 upvar_id. closure_expr_id ,
629639 ty:: ClosureKind :: FnOnce ,
630640 usage_span,
631- var_name ( tcx , upvar_id . var_path . hir_id ) ,
641+ place_with_id . place . clone ( ) ,
632642 ) ;
633643
634644 let capture_info = ty:: CaptureInfo {
@@ -720,7 +730,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
720730 upvar_id. closure_expr_id ,
721731 ty:: ClosureKind :: FnMut ,
722732 tcx. hir ( ) . span ( diag_expr_id) ,
723- var_name ( tcx , upvar_id . var_path . hir_id ) ,
733+ place_with_id . place . clone ( ) ,
724734 ) ;
725735 }
726736 }
@@ -765,11 +775,11 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
765775 closure_id : LocalDefId ,
766776 new_kind : ty:: ClosureKind ,
767777 upvar_span : Span ,
768- var_name : Symbol ,
778+ place : Place < ' tcx > ,
769779 ) {
770780 debug ! (
771- "adjust_closure_kind(closure_id={:?}, new_kind={:?}, upvar_span={:?}, var_name={ })" ,
772- closure_id, new_kind, upvar_span, var_name
781+ "adjust_closure_kind(closure_id={:?}, new_kind={:?}, upvar_span={:?}, place={:? })" ,
782+ closure_id, new_kind, upvar_span, place
773783 ) ;
774784
775785 // Is this the closure whose kind is currently being inferred?
@@ -797,7 +807,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
797807 | ( ty:: ClosureKind :: FnMut , ty:: ClosureKind :: FnOnce ) => {
798808 // new kind is stronger than the old kind
799809 self . current_closure_kind = new_kind;
800- self . current_origin = Some ( ( upvar_span, var_name ) ) ;
810+ self . current_origin = Some ( ( upvar_span, place ) ) ;
801811 }
802812 }
803813 }
0 commit comments