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