@@ -326,6 +326,7 @@ fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetime
326326 }
327327
328328 debug ! ( ?rl. defs) ;
329+ debug ! ( ?rl. late_bound_vars) ;
329330 rl
330331}
331332
@@ -507,7 +508,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
507508 } )
508509 . unzip ( ) ;
509510
510- self . map . late_bound_vars . insert ( e. hir_id , binders) ;
511+ self . record_late_bound_vars ( e. hir_id , binders) ;
511512 let scope = Scope :: Binder {
512513 hir_id : e. hir_id ,
513514 lifetimes,
@@ -531,7 +532,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
531532 match & item. kind {
532533 hir:: ItemKind :: Impl ( hir:: Impl { of_trait, .. } ) => {
533534 if let Some ( of_trait) = of_trait {
534- self . map . late_bound_vars . insert ( of_trait. hir_ref_id , Vec :: default ( ) ) ;
535+ self . record_late_bound_vars ( of_trait. hir_ref_id , Vec :: default ( ) ) ;
535536 }
536537 }
537538 _ => { }
@@ -583,7 +584,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
583584 resolved_lifetimes. late_bound_vars . iter ( )
584585 {
585586 late_bound_vars. iter ( ) . for_each ( |( & local_id, late_bound_vars) | {
586- self . map . late_bound_vars . insert (
587+ self . record_late_bound_vars (
587588 hir:: HirId { owner, local_id } ,
588589 late_bound_vars. clone ( ) ,
589590 ) ;
@@ -614,7 +615,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
614615 GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => None ,
615616 } )
616617 . collect ( ) ;
617- self . map . late_bound_vars . insert ( item. hir_id ( ) , vec ! [ ] ) ;
618+ self . record_late_bound_vars ( item. hir_id ( ) , vec ! [ ] ) ;
618619 let scope = Scope :: Binder {
619620 hir_id : item. hir_id ( ) ,
620621 lifetimes,
@@ -663,7 +664,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
663664 ( pair, r)
664665 } )
665666 . unzip ( ) ;
666- self . map . late_bound_vars . insert ( ty. hir_id , binders) ;
667+ self . record_late_bound_vars ( ty. hir_id , binders) ;
667668 let scope = Scope :: Binder {
668669 hir_id : ty. hir_id ,
669670 lifetimes,
@@ -817,7 +818,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
817818 GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => { }
818819 }
819820 }
820- self . map . late_bound_vars . insert ( ty. hir_id , vec ! [ ] ) ;
821+ self . record_late_bound_vars ( ty. hir_id , vec ! [ ] ) ;
821822
822823 let scope = Scope :: Binder {
823824 hir_id : ty. hir_id ,
@@ -861,7 +862,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
861862 GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => None ,
862863 } )
863864 . collect ( ) ;
864- self . map . late_bound_vars . insert ( trait_item. hir_id ( ) , vec ! [ ] ) ;
865+ self . record_late_bound_vars ( trait_item. hir_id ( ) , vec ! [ ] ) ;
865866 let scope = Scope :: Binder {
866867 hir_id : trait_item. hir_id ( ) ,
867868 lifetimes,
@@ -909,9 +910,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
909910 GenericParamKind :: Const { .. } | GenericParamKind :: Type { .. } => None ,
910911 } )
911912 . collect ( ) ;
912- self . map . late_bound_vars . insert ( ty . hir_id , vec ! [ ] ) ;
913+ self . record_late_bound_vars ( impl_item . hir_id ( ) , vec ! [ ] ) ;
913914 let scope = Scope :: Binder {
914- hir_id : ty . hir_id ,
915+ hir_id : impl_item . hir_id ( ) ,
915916 lifetimes,
916917 s : self . scope ,
917918 scope_type : BinderScopeType :: Normal ,
@@ -995,33 +996,38 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
995996 for predicate in generics. predicates {
996997 match predicate {
997998 & hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
999+ hir_id,
9981000 ref bounded_ty,
9991001 bounds,
10001002 ref bound_generic_params,
10011003 origin,
10021004 ..
10031005 } ) => {
1004- let ( lifetimes, binders ) : ( FxIndexMap < LocalDefId , Region > , Vec < _ > ) =
1006+ let lifetimes: FxIndexMap < LocalDefId , Region > =
10051007 bound_generic_params
10061008 . iter ( )
10071009 . filter ( |param| {
10081010 matches ! ( param. kind, GenericParamKind :: Lifetime { .. } )
10091011 } )
10101012 . enumerate ( )
10111013 . map ( |( late_bound_idx, param) | {
1012- let pair =
1013- Region :: late ( late_bound_idx as u32 , this. tcx . hir ( ) , param) ;
1014- let r = late_region_as_bound_region ( this. tcx , & pair. 1 ) ;
1015- ( pair, r)
1014+ Region :: late ( late_bound_idx as u32 , this. tcx . hir ( ) , param)
1015+ } )
1016+ . collect ( ) ;
1017+ let binders: Vec < _ > =
1018+ lifetimes
1019+ . iter ( )
1020+ . map ( |( _, region) | {
1021+ late_region_as_bound_region ( this. tcx , region)
10161022 } )
1017- . unzip ( ) ;
1018- this. map . late_bound_vars . insert ( bounded_ty . hir_id , binders. clone ( ) ) ;
1023+ . collect ( ) ;
1024+ this. record_late_bound_vars ( hir_id, binders. clone ( ) ) ;
10191025 // Even if there are no lifetimes defined here, we still wrap it in a binder
10201026 // scope. If there happens to be a nested poly trait ref (an error), that
10211027 // will be `Concatenating` anyways, so we don't have to worry about the depth
10221028 // being wrong.
10231029 let scope = Scope :: Binder {
1024- hir_id : bounded_ty . hir_id ,
1030+ hir_id,
10251031 lifetimes,
10261032 s : this. scope ,
10271033 scope_type : BinderScopeType :: Normal ,
@@ -1089,7 +1095,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10891095 // imagine there's a better way to go about this.
10901096 let ( binders, scope_type) = self . poly_trait_ref_binder_info ( ) ;
10911097
1092- self . map . late_bound_vars . insert ( * hir_id, binders) ;
1098+ self . record_late_bound_vars ( * hir_id, binders) ;
10931099 let scope = Scope :: Binder {
10941100 hir_id : * hir_id,
10951101 lifetimes : FxIndexMap :: default ( ) ,
@@ -1127,7 +1133,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11271133 binders. extend ( binders_iter) ;
11281134
11291135 debug ! ( ?binders) ;
1130- self . map . late_bound_vars . insert ( trait_ref. trait_ref . hir_ref_id , binders) ;
1136+ self . record_late_bound_vars ( trait_ref. trait_ref . hir_ref_id , binders) ;
11311137
11321138 // Always introduce a scope here, even if this is in a where clause and
11331139 // we introduced the binders around the bounded Ty. In that case, we
@@ -1211,6 +1217,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
12111217 }
12121218 }
12131219
1220+ fn record_late_bound_vars ( & mut self , hir_id : hir:: HirId , binder : Vec < ty:: BoundVariableKind > ) {
1221+ if let Some ( old) = self . map . late_bound_vars . insert ( hir_id, binder) {
1222+ bug ! (
1223+ "overwrote bound vars for {hir_id:?}:\n old={old:?}\n new={:?}" ,
1224+ self . map. late_bound_vars[ & hir_id]
1225+ )
1226+ }
1227+ }
1228+
12141229 /// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
12151230 ///
12161231 /// Handles visiting fns and methods. These are a bit complicated because we must distinguish
@@ -1268,7 +1283,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
12681283 late_region_as_bound_region ( self . tcx , & pair. 1 )
12691284 } )
12701285 . collect ( ) ;
1271- self . map . late_bound_vars . insert ( hir_id, binders) ;
1286+ self . record_late_bound_vars ( hir_id, binders) ;
12721287 let scope = Scope :: Binder {
12731288 hir_id,
12741289 lifetimes,
0 commit comments