@@ -550,16 +550,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
550550}
551551
552552impl < ' a , ' tcx > Visitor < ' tcx > for TypeChecker < ' a , ' tcx > {
553- fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
554- if let Rvalue :: Reborrow ( mutability, rvalue, _) = rvalue {
555- // check rvalue is Reborrow
556- self . add_generic_reborrow_constraint ( * mutability, location, place, rvalue) ;
557- } else {
558- // rest of the cases
559- self . super_assign ( place, rvalue, location) ;
560- }
561- }
562-
563553 fn visit_span ( & mut self , span : Span ) {
564554 if !span. is_dummy ( ) {
565555 debug ! ( ?span) ;
@@ -637,10 +627,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
637627 debug ! ( ?rv_ty) ;
638628 let rv_ty = self . normalize ( rv_ty, location) ;
639629 debug ! ( "normalized rv_ty: {:?}" , rv_ty) ;
640- if let Rvalue :: Reborrow ( mutability, rvalue, _) = rv {
641- // check rvalue is Reborrow
642- self . add_generic_reborrow_constraint ( * mutability, location, place, rvalue) ;
643- } else if let Err ( terr) =
630+ if let Err ( terr) =
644631 self . sub_types ( rv_ty, place_ty, location. to_locations ( ) , category)
645632 {
646633 span_mirbug ! (
@@ -1594,10 +1581,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15941581 self . add_reborrow_constraint ( location, * region, borrowed_place) ;
15951582 }
15961583
1597- Rvalue :: Reborrow ( .. ) => {
1584+ Rvalue :: Reborrow ( target , mutability , borrowed_place ) => {
15981585 // Reborrow needs to produce a relation between the source and destination fields,
15991586 // which means that we have had to already handle this in visit_assign.
1600- unreachable ! ( )
1587+ self . add_generic_reborrow_constraint (
1588+ * mutability,
1589+ location,
1590+ borrowed_place,
1591+ * target,
1592+ ) ;
16011593 }
16021594
16031595 Rvalue :: BinaryOp (
@@ -2445,8 +2437,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24452437 & mut self ,
24462438 mutability : Mutability ,
24472439 location : Location ,
2448- dest : & Place < ' tcx > ,
24492440 borrowed_place : & Place < ' tcx > ,
2441+ dest_ty : Ty < ' tcx > ,
24502442 ) {
24512443 // These constraints are only meaningful during borrowck:
24522444 let Self { borrow_set, location_table, polonius_facts, constraints, infcx, body, .. } =
@@ -2459,7 +2451,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24592451
24602452 debug ! (
24612453 "add_generic_reborrow_constraint({:?}, {:?}, {:?}, {:?})" ,
2462- mutability, location, dest , borrowed_place
2454+ mutability, location, borrowed_place , dest_ty
24632455 ) ;
24642456
24652457 let tcx = infcx. tcx ;
@@ -2473,19 +2465,19 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24732465 ConstraintCategory :: Boring
24742466 } ;
24752467
2476- let dest_ty = dest. ty ( self . body , tcx) . ty ;
24772468 let borrowed_ty = borrowed_place. ty ( self . body , tcx) . ty ;
2478- let ty:: Adt ( _, args) = dest_ty. kind ( ) else { bug ! ( ) } ;
2479- let [ arg, ..] = * * * args else { bug ! ( ) } ;
2480- let ty:: GenericArgKind :: Lifetime ( reborrow_region) = arg. kind ( ) else { bug ! ( ) } ;
2481- constraints. liveness_constraints . add_location ( reborrow_region. as_var ( ) , location) ;
2469+
2470+ let ty:: Adt ( dest_adt, dest_args) = dest_ty. kind ( ) else { bug ! ( ) } ;
2471+ let [ dest_arg, ..] = * * * dest_args else { bug ! ( ) } ;
2472+ let ty:: GenericArgKind :: Lifetime ( dest_region) = dest_arg. kind ( ) else { bug ! ( ) } ;
2473+ constraints. liveness_constraints . add_location ( dest_region. as_var ( ) , location) ;
24822474
24832475 // In Polonius mode, we also push a `loan_issued_at` fact
24842476 // linking the loan to the region.
24852477 if let Some ( polonius_facts) = polonius_facts {
24862478 let _prof_timer = infcx. tcx . prof . generic_activity ( "polonius_fact_generation" ) ;
24872479 if let Some ( borrow_index) = borrow_set. get_index_of ( & location) {
2488- let region_vid = reborrow_region . as_var ( ) ;
2480+ let region_vid = dest_region . as_var ( ) ;
24892481 polonius_facts. loan_issued_at . push ( (
24902482 region_vid. into ( ) ,
24912483 borrow_index,
@@ -2501,7 +2493,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25012493 // `CustomMut<'a>` and `CustomRef<'a>`, or `CustomMut<'a, T>` and `CustomRef<'a, T>`.
25022494 // Field-by-field relate_types is expected to work based on the wf-checks that the
25032495 // CoerceShared trait performs.
2504- let ty:: Adt ( dest_adt, dest_args) = dest_ty. kind ( ) else { unreachable ! ( ) } ;
25052496 let ty:: Adt ( borrowed_adt, borrowed_args) = borrowed_ty. kind ( ) else { unreachable ! ( ) } ;
25062497 let borrowed_fields = borrowed_adt. all_fields ( ) . collect :: < Vec < _ > > ( ) ;
25072498 for dest_field in dest_adt. all_fields ( ) {
0 commit comments