@@ -476,12 +476,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
476476 let mut indices = self . compute_indices ( fr_static, defining_ty) ;
477477 debug ! ( "build: indices={:?}" , indices) ;
478478
479- let typeck_root_def_id = self . infcx . tcx . typeck_root_def_id ( self . mir_def . to_def_id ( ) ) ;
480-
481479 // If this is a 'root' body (not a closure/coroutine/inline const), then
482480 // there are no extern regions, so the local regions start at the same
483481 // position as the (empty) sub-list of extern regions
484- let first_local_index = if self . mir_def . to_def_id ( ) == typeck_root_def_id {
482+ let first_local_index = if ! self . infcx . tcx . is_typeck_child ( self . mir_def . to_def_id ( ) ) {
485483 first_extern_index
486484 } else {
487485 // If this is a closure, coroutine, or inline-const, then the late-bound regions from the enclosing
@@ -583,7 +581,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
583581 /// see `DefiningTy` for details.
584582 fn defining_ty ( & self ) -> DefiningTy < ' tcx > {
585583 let tcx = self . infcx . tcx ;
586- let typeck_root_def_id = tcx. typeck_root_def_id ( self . mir_def . to_def_id ( ) ) ;
584+ let typeck_root_def_id = tcx. typeck_root_def_id_local ( self . mir_def ) ;
587585
588586 match tcx. hir_body_owner_kind ( self . mir_def ) {
589587 BodyOwnerKind :: Closure | BodyOwnerKind :: Fn => {
@@ -614,7 +612,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
614612
615613 BodyOwnerKind :: Const { .. } | BodyOwnerKind :: Static ( ..) => {
616614 let identity_args = GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
617- if self . mir_def . to_def_id ( ) == typeck_root_def_id {
615+ if self . mir_def == typeck_root_def_id {
618616 let args = self . infcx . replace_free_regions_with_nll_infer_vars (
619617 NllRegionVariableOrigin :: FreeRegion ,
620618 identity_args,
@@ -660,7 +658,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
660658 defining_ty : DefiningTy < ' tcx > ,
661659 ) -> UniversalRegionIndices < ' tcx > {
662660 let tcx = self . infcx . tcx ;
663- let typeck_root_def_id = tcx. typeck_root_def_id ( self . mir_def . to_def_id ( ) ) ;
661+ let typeck_root_def_id = tcx. typeck_root_def_id_local ( self . mir_def ) ;
664662 let identity_args = GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
665663 let renumbered_args = defining_ty. args ( ) ;
666664
@@ -948,16 +946,14 @@ fn for_each_late_bound_region_in_recursive_scope<'tcx>(
948946 mut mir_def_id : LocalDefId ,
949947 mut f : impl FnMut ( ty:: Region < ' tcx > ) ,
950948) {
951- let typeck_root_def_id = tcx. typeck_root_def_id ( mir_def_id. to_def_id ( ) ) ;
952-
953949 // Walk up the tree, collecting late-bound regions until we hit the typeck root
954950 loop {
955951 for_each_late_bound_region_in_item ( tcx, mir_def_id, & mut f) ;
956952
957- if mir_def_id. to_def_id ( ) == typeck_root_def_id {
958- break ;
959- } else {
953+ if tcx. is_typeck_child ( mir_def_id. to_def_id ( ) ) {
960954 mir_def_id = tcx. local_parent ( mir_def_id) ;
955+ } else {
956+ break ;
961957 }
962958 }
963959}
0 commit comments