1
+ use rustc_data_structures:: fx:: FxHashSet ;
1
2
use rustc_hir:: def_id:: LocalDefId ;
2
3
use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
3
4
use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
@@ -7,7 +8,7 @@ use rustc_infer::infer::{InferCtxt, SubregionOrigin};
7
8
use rustc_infer:: traits:: query:: type_op:: DeeplyNormalize ;
8
9
use rustc_middle:: bug;
9
10
use rustc_middle:: ty:: {
10
- self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt , fold_regions,
11
+ self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt , elaborate , fold_regions,
11
12
} ;
12
13
use rustc_span:: Span ;
13
14
use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
@@ -70,10 +71,12 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
70
71
71
72
#[ instrument( skip( self ) , level = "debug" ) ]
72
73
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 ( ) ) ;
74
77
75
78
for & ( predicate, constraint_category) in outlives {
76
- self . convert ( predicate, constraint_category) ;
79
+ self . convert ( predicate, constraint_category, & assumptions ) ;
77
80
}
78
81
}
79
82
@@ -112,7 +115,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
112
115
113
116
self . category = outlives_requirement. category ;
114
117
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
+ ) ;
116
123
}
117
124
( self . category , self . span , self . from_closure ) = backup;
118
125
}
@@ -121,6 +128,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
121
128
& mut self ,
122
129
predicate : ty:: OutlivesPredicate < ' tcx , ty:: GenericArg < ' tcx > > ,
123
130
constraint_category : ConstraintCategory < ' tcx > ,
131
+ higher_ranked_assumptions : & FxHashSet < ty:: OutlivesPredicate < ' tcx , ty:: GenericArg < ' tcx > > > ,
124
132
) {
125
133
let tcx = self . infcx . tcx ;
126
134
debug ! ( "generate: constraints at: {:#?}" , self . locations) ;
@@ -150,7 +158,13 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
150
158
}
151
159
152
160
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;
154
168
match k1. kind ( ) {
155
169
GenericArgKind :: Lifetime ( r1) => {
156
170
let r1_vid = self . to_region_vid ( r1) ;
@@ -273,7 +287,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
273
287
match self . param_env . and ( DeeplyNormalize { value : ty } ) . fully_perform ( self . infcx , self . span )
274
288
{
275
289
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 {
277
292
next_outlives_predicates. extend ( outlives. iter ( ) . copied ( ) ) ;
278
293
}
279
294
ty
0 commit comments