@@ -463,7 +463,20 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
463
463
target : _,
464
464
unwind : _,
465
465
} => {
466
- self . visit_terminator_drop ( loc, term, flow_state, drop_place, span) ;
466
+ let gcx = self . tcx . global_tcx ( ) ;
467
+
468
+ // Compute the type with accurate region information.
469
+ let drop_place_ty = drop_place. ty ( self . mir , self . tcx ) ;
470
+
471
+ // Erase the regions.
472
+ let drop_place_ty = self . tcx . erase_regions ( & drop_place_ty) . to_ty ( self . tcx ) ;
473
+
474
+ // "Lift" into the gcx -- once regions are erased, this type should be in the
475
+ // global arenas; this "lift" operation basically just asserts that is true, but
476
+ // that is useful later.
477
+ let drop_place_ty = gcx. lift ( & drop_place_ty) . unwrap ( ) ;
478
+
479
+ self . visit_terminator_drop ( loc, term, flow_state, drop_place, drop_place_ty, span) ;
467
480
}
468
481
TerminatorKind :: DropAndReplace {
469
482
location : ref drop_place,
@@ -723,10 +736,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
723
736
term : & Terminator < ' tcx > ,
724
737
flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
725
738
drop_place : & Place < ' tcx > ,
739
+ erased_drop_place_ty : ty:: Ty < ' gcx > ,
726
740
span : Span ,
727
741
) {
728
- let ty = drop_place. ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
729
- match ty. sty {
742
+ match erased_drop_place_ty. sty {
730
743
// When a struct is being dropped, we need to check
731
744
// whether it has a destructor, if it does, then we can
732
745
// call it, if it does not then we need to check the
@@ -735,14 +748,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
735
748
// borrows of `x.foo` and not `x.bar`. See #47703.
736
749
ty:: TyAdt ( def, substs) if def. is_struct ( ) && !def. has_dtor ( self . tcx ) => {
737
750
for ( index, field) in def. all_fields ( ) . enumerate ( ) {
738
- let place = drop_place. clone ( ) ;
739
- let place = place. field ( Field :: new ( index) , field. ty ( self . tcx , substs) ) ;
751
+ let gcx = self . tcx . global_tcx ( ) ;
752
+ let field_ty = field. ty ( gcx, substs) ;
753
+ let field_ty = gcx. normalize_associated_type_in_env ( & field_ty, self . param_env ) ;
754
+ let place = drop_place. clone ( ) . field ( Field :: new ( index) , field_ty) ;
740
755
741
756
self . visit_terminator_drop (
742
757
loc,
743
758
term,
744
759
flow_state,
745
760
& place,
761
+ field_ty,
746
762
span,
747
763
) ;
748
764
}
@@ -754,8 +770,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
754
770
// "needs drop". If so, we assume that the destructor
755
771
// may access any data it likes (i.e., a Deep Write).
756
772
let gcx = self . tcx . global_tcx ( ) ;
757
- let erased_ty = gcx. lift ( & self . tcx . erase_regions ( & ty) ) . unwrap ( ) ;
758
- if erased_ty. needs_drop ( gcx, self . param_env ) {
773
+ if erased_drop_place_ty. needs_drop ( gcx, self . param_env ) {
759
774
self . access_place (
760
775
ContextKind :: Drop . new ( loc) ,
761
776
( drop_place, span) ,
@@ -2144,7 +2159,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2144
2159
while let Some ( i) = elems_incoming. next ( ) {
2145
2160
let borrowed = & data[ i. borrow_index ( ) ] ;
2146
2161
2147
- if self . places_conflict ( & borrowed. borrowed_place , & place, access) {
2162
+ if self . places_conflict ( & borrowed. borrowed_place , place, access) {
2148
2163
debug ! ( "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}" ,
2149
2164
i, borrowed, place, access) ;
2150
2165
let ctrl = op ( self , i, borrowed) ;
0 commit comments