@@ -326,6 +326,7 @@ fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetime
326
326
}
327
327
328
328
debug ! ( ?rl. defs) ;
329
+ debug ! ( ?rl. late_bound_vars) ;
329
330
rl
330
331
}
331
332
@@ -507,7 +508,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
507
508
} )
508
509
. unzip ( ) ;
509
510
510
- self . map . late_bound_vars . insert ( e. hir_id , binders) ;
511
+ self . record_late_bound_vars ( e. hir_id , binders) ;
511
512
let scope = Scope :: Binder {
512
513
hir_id : e. hir_id ,
513
514
lifetimes,
@@ -531,7 +532,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
531
532
match & item. kind {
532
533
hir:: ItemKind :: Impl ( hir:: Impl { of_trait, .. } ) => {
533
534
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 ( ) ) ;
535
536
}
536
537
}
537
538
_ => { }
@@ -583,7 +584,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
583
584
resolved_lifetimes. late_bound_vars . iter ( )
584
585
{
585
586
late_bound_vars. iter ( ) . for_each ( |( & local_id, late_bound_vars) | {
586
- self . map . late_bound_vars . insert (
587
+ self . record_late_bound_vars (
587
588
hir:: HirId { owner, local_id } ,
588
589
late_bound_vars. clone ( ) ,
589
590
) ;
@@ -614,7 +615,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
614
615
GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => None ,
615
616
} )
616
617
. collect ( ) ;
617
- self . map . late_bound_vars . insert ( item. hir_id ( ) , vec ! [ ] ) ;
618
+ self . record_late_bound_vars ( item. hir_id ( ) , vec ! [ ] ) ;
618
619
let scope = Scope :: Binder {
619
620
hir_id : item. hir_id ( ) ,
620
621
lifetimes,
@@ -663,7 +664,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
663
664
( pair, r)
664
665
} )
665
666
. unzip ( ) ;
666
- self . map . late_bound_vars . insert ( ty. hir_id , binders) ;
667
+ self . record_late_bound_vars ( ty. hir_id , binders) ;
667
668
let scope = Scope :: Binder {
668
669
hir_id : ty. hir_id ,
669
670
lifetimes,
@@ -817,7 +818,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
817
818
GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => { }
818
819
}
819
820
}
820
- self . map . late_bound_vars . insert ( ty. hir_id , vec ! [ ] ) ;
821
+ self . record_late_bound_vars ( ty. hir_id , vec ! [ ] ) ;
821
822
822
823
let scope = Scope :: Binder {
823
824
hir_id : ty. hir_id ,
@@ -861,7 +862,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
861
862
GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => None ,
862
863
} )
863
864
. collect ( ) ;
864
- self . map . late_bound_vars . insert ( trait_item. hir_id ( ) , vec ! [ ] ) ;
865
+ self . record_late_bound_vars ( trait_item. hir_id ( ) , vec ! [ ] ) ;
865
866
let scope = Scope :: Binder {
866
867
hir_id : trait_item. hir_id ( ) ,
867
868
lifetimes,
@@ -909,9 +910,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
909
910
GenericParamKind :: Const { .. } | GenericParamKind :: Type { .. } => None ,
910
911
} )
911
912
. collect ( ) ;
912
- self . map . late_bound_vars . insert ( ty . hir_id , vec ! [ ] ) ;
913
+ self . record_late_bound_vars ( impl_item . hir_id ( ) , vec ! [ ] ) ;
913
914
let scope = Scope :: Binder {
914
- hir_id : ty . hir_id ,
915
+ hir_id : impl_item . hir_id ( ) ,
915
916
lifetimes,
916
917
s : self . scope ,
917
918
scope_type : BinderScopeType :: Normal ,
@@ -995,33 +996,38 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
995
996
for predicate in generics. predicates {
996
997
match predicate {
997
998
& hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
999
+ hir_id,
998
1000
ref bounded_ty,
999
1001
bounds,
1000
1002
ref bound_generic_params,
1001
1003
origin,
1002
1004
..
1003
1005
} ) => {
1004
- let ( lifetimes, binders ) : ( FxIndexMap < LocalDefId , Region > , Vec < _ > ) =
1006
+ let lifetimes: FxIndexMap < LocalDefId , Region > =
1005
1007
bound_generic_params
1006
1008
. iter ( )
1007
1009
. filter ( |param| {
1008
1010
matches ! ( param. kind, GenericParamKind :: Lifetime { .. } )
1009
1011
} )
1010
1012
. enumerate ( )
1011
1013
. 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)
1016
1022
} )
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 ( ) ) ;
1019
1025
// Even if there are no lifetimes defined here, we still wrap it in a binder
1020
1026
// scope. If there happens to be a nested poly trait ref (an error), that
1021
1027
// will be `Concatenating` anyways, so we don't have to worry about the depth
1022
1028
// being wrong.
1023
1029
let scope = Scope :: Binder {
1024
- hir_id : bounded_ty . hir_id ,
1030
+ hir_id,
1025
1031
lifetimes,
1026
1032
s : this. scope ,
1027
1033
scope_type : BinderScopeType :: Normal ,
@@ -1089,7 +1095,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1089
1095
// imagine there's a better way to go about this.
1090
1096
let ( binders, scope_type) = self . poly_trait_ref_binder_info ( ) ;
1091
1097
1092
- self . map . late_bound_vars . insert ( * hir_id, binders) ;
1098
+ self . record_late_bound_vars ( * hir_id, binders) ;
1093
1099
let scope = Scope :: Binder {
1094
1100
hir_id : * hir_id,
1095
1101
lifetimes : FxIndexMap :: default ( ) ,
@@ -1127,7 +1133,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1127
1133
binders. extend ( binders_iter) ;
1128
1134
1129
1135
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) ;
1131
1137
1132
1138
// Always introduce a scope here, even if this is in a where clause and
1133
1139
// we introduced the binders around the bounded Ty. In that case, we
@@ -1211,6 +1217,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1211
1217
}
1212
1218
}
1213
1219
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
+
1214
1229
/// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
1215
1230
///
1216
1231
/// Handles visiting fns and methods. These are a bit complicated because we must distinguish
@@ -1268,7 +1283,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1268
1283
late_region_as_bound_region ( self . tcx , & pair. 1 )
1269
1284
} )
1270
1285
. collect ( ) ;
1271
- self . map . late_bound_vars . insert ( hir_id, binders) ;
1286
+ self . record_late_bound_vars ( hir_id, binders) ;
1272
1287
let scope = Scope :: Binder {
1273
1288
hir_id,
1274
1289
lifetimes,
0 commit comments