@@ -916,6 +916,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
916
916
/// The idea then is to lower the `T: 'X` constraint into multiple
917
917
/// bounds -- e.g., if `'X` is the union of two free lifetimes,
918
918
/// `'1` and `'2`, then we would create `T: '1` and `T: '2`.
919
+ #[ instrument( level = "debug" , skip( self , infcx, propagated_outlives_requirements) ) ]
919
920
fn try_promote_type_test (
920
921
& self ,
921
922
infcx : & InferCtxt < ' _ , ' tcx > ,
@@ -933,11 +934,41 @@ impl<'tcx> RegionInferenceContext<'tcx> {
933
934
return false ;
934
935
} ;
935
936
937
+ debug ! ( "subject = {:?}" , subject) ;
938
+
939
+ let r_scc = self . constraint_sccs . scc ( * lower_bound) ;
940
+
941
+ debug ! (
942
+ "lower_bound = {:?} r_scc={:?} universe={:?}" ,
943
+ lower_bound, r_scc, self . scc_universes[ r_scc]
944
+ ) ;
945
+
946
+ // If the type test requires that `T: 'a` where `'a` is a
947
+ // placeholder from another universe, that effectively requires
948
+ // `T: 'static`, so we have to propagate that requirement.
949
+ //
950
+ // It doesn't matter *what* universe because the promoted `T` will
951
+ // always be in the root universe.
952
+ if let Some ( p) = self . scc_values . placeholders_contained_in ( r_scc) . next ( ) {
953
+ debug ! ( "encountered placeholder in higher universe: {:?}, requiring 'static" , p) ;
954
+ let static_r = self . universal_regions . fr_static ;
955
+ propagated_outlives_requirements. push ( ClosureOutlivesRequirement {
956
+ subject,
957
+ outlived_free_region : static_r,
958
+ blame_span : locations. span ( body) ,
959
+ category : ConstraintCategory :: Boring ,
960
+ } ) ;
961
+
962
+ // we can return here -- the code below might push add'l constraints
963
+ // but they would all be weaker than this one.
964
+ return true ;
965
+ }
966
+
936
967
// For each region outlived by lower_bound find a non-local,
937
968
// universal region (it may be the same region) and add it to
938
969
// `ClosureOutlivesRequirement`.
939
- let r_scc = self . constraint_sccs . scc ( * lower_bound) ;
940
970
for ur in self . scc_values . universal_regions_outlived_by ( r_scc) {
971
+ debug ! ( "universal_region_outlived_by ur={:?}" , ur) ;
941
972
// Check whether we can already prove that the "subject" outlives `ur`.
942
973
// If so, we don't have to propagate this requirement to our caller.
943
974
//
@@ -962,8 +993,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
962
993
continue ;
963
994
}
964
995
965
- debug ! ( "try_promote_type_test: ur={:?}" , ur) ;
966
-
967
996
let non_local_ub = self . universal_region_relations . non_local_upper_bounds ( ur) ;
968
997
debug ! ( "try_promote_type_test: non_local_ub={:?}" , non_local_ub) ;
969
998
@@ -1000,15 +1029,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1000
1029
/// will use it's *external name*, which will be a `RegionKind`
1001
1030
/// variant that can be used in query responses such as
1002
1031
/// `ReEarlyBound`.
1032
+ #[ instrument( level = "debug" , skip( self , infcx) ) ]
1003
1033
fn try_promote_type_test_subject (
1004
1034
& self ,
1005
1035
infcx : & InferCtxt < ' _ , ' tcx > ,
1006
1036
ty : Ty < ' tcx > ,
1007
1037
) -> Option < ClosureOutlivesSubject < ' tcx > > {
1008
1038
let tcx = infcx. tcx ;
1009
1039
1010
- debug ! ( "try_promote_type_test_subject(ty = {:?})" , ty) ;
1011
-
1012
1040
let ty = tcx. fold_regions ( ty, |r, _depth| {
1013
1041
let region_vid = self . to_region_vid ( r) ;
1014
1042
0 commit comments