1+ use rustc_data_structures:: fx:: FxHashSet ;
12use rustc_hir:: def_id:: LocalDefId ;
23use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
34use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
@@ -7,7 +8,7 @@ use rustc_infer::infer::{InferCtxt, SubregionOrigin};
78use rustc_infer:: traits:: query:: type_op:: DeeplyNormalize ;
89use rustc_middle:: bug;
910use rustc_middle:: ty:: {
10- self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt , fold_regions,
11+ self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt , elaborate , fold_regions,
1112} ;
1213use rustc_span:: Span ;
1314use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
@@ -70,10 +71,12 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
7071
7172 #[ instrument( skip( self ) , level = "debug" ) ]
7273 pub ( super ) fn convert_all ( & mut self , query_constraints : & QueryRegionConstraints < ' tcx > ) {
73- let QueryRegionConstraints { outlives } = query_constraints;
74+ let QueryRegionConstraints { outlives, assumptions } = query_constraints;
75+ let assumptions =
76+ elaborate:: elaborate_outlives_assumptions ( self . infcx . tcx , assumptions. iter ( ) . copied ( ) ) ;
7477
7578 for & ( predicate, constraint_category) in outlives {
76- self . convert ( predicate, constraint_category) ;
79+ self . convert ( predicate, constraint_category, & assumptions ) ;
7780 }
7881 }
7982
@@ -112,7 +115,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
112115
113116 self . category = outlives_requirement. category ;
114117 self . span = outlives_requirement. blame_span ;
115- self . convert ( ty:: OutlivesPredicate ( subject, outlived_region) , self . category ) ;
118+ self . convert (
119+ ty:: OutlivesPredicate ( subject, outlived_region) ,
120+ self . category ,
121+ & Default :: default ( ) ,
122+ ) ;
116123 }
117124 ( self . category , self . span , self . from_closure ) = backup;
118125 }
@@ -121,6 +128,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
121128 & mut self ,
122129 predicate : ty:: OutlivesPredicate < ' tcx , ty:: GenericArg < ' tcx > > ,
123130 constraint_category : ConstraintCategory < ' tcx > ,
131+ higher_ranked_assumptions : & FxHashSet < ty:: OutlivesPredicate < ' tcx , ty:: GenericArg < ' tcx > > > ,
124132 ) {
125133 let tcx = self . infcx . tcx ;
126134 debug ! ( "generate: constraints at: {:#?}" , self . locations) ;
@@ -150,7 +158,13 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
150158 }
151159
152160 let mut next_outlives_predicates = vec ! [ ] ;
153- for ( ty:: OutlivesPredicate ( k1, r2) , constraint_category) in outlives_predicates {
161+ for ( pred, constraint_category) in outlives_predicates {
162+ // Constraint is implied by a coroutine's well-formedness.
163+ if higher_ranked_assumptions. contains ( & pred) {
164+ continue ;
165+ }
166+
167+ let ty:: OutlivesPredicate ( k1, r2) = pred;
154168 match k1. kind ( ) {
155169 GenericArgKind :: Lifetime ( r1) => {
156170 let r1_vid = self . to_region_vid ( r1) ;
@@ -273,7 +287,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
273287 match self . param_env . and ( DeeplyNormalize { value : ty } ) . fully_perform ( self . infcx , self . span )
274288 {
275289 Ok ( TypeOpOutput { output : ty, constraints, .. } ) => {
276- if let Some ( QueryRegionConstraints { outlives } ) = constraints {
290+ // FIXME(higher_ranked_auto): What should we do with the assumptions here?
291+ if let Some ( QueryRegionConstraints { outlives, assumptions : _ } ) = constraints {
277292 next_outlives_predicates. extend ( outlives. iter ( ) . copied ( ) ) ;
278293 }
279294 ty
0 commit comments