@@ -5,14 +5,11 @@ use rustc_infer::infer::canonical::{QueryRegionConstraint, QueryRegionConstraint
55use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
66use rustc_infer:: infer:: outlives:: obligations:: { TypeOutlives , TypeOutlivesDelegate } ;
77use rustc_infer:: infer:: region_constraints:: { GenericKind , VerifyBound } ;
8- use rustc_infer:: traits:: query:: type_op:: Normalize ;
9- use rustc_middle:: bug;
108use rustc_middle:: ty:: {
11- self , GenericArgKind , RegionExt , RegionUtilitiesExt , Ty , TyCtxt , TypeFoldable ,
12- TypeVisitableExt , elaborate, fold_regions,
9+ self , GenericArgKind , RegionExt , RegionUtilitiesExt , TyCtxt , TypeFoldable , TypeVisitableExt ,
10+ elaborate, fold_regions,
1311} ;
1412use rustc_span:: Span ;
15- use rustc_trait_selection:: traits:: query:: type_op:: TypeOpOutput ;
1613use tracing:: { debug, instrument} ;
1714
1815use crate :: constraints:: OutlivesConstraint ;
@@ -137,83 +134,49 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
137134
138135 // Extract out various useful fields we'll need below.
139136 let ConstraintConversion {
140- infcx,
137+ infcx : _ ,
141138 universal_regions,
142139 region_bound_pairs,
143140 known_type_outlives_obligations,
144141 ..
145142 } = * self ;
146143
147- let mut outlives_predicates = vec ! [ ( predicate, constraint_category) ] ;
148- for iteration in 0 .. {
149- if outlives_predicates. is_empty ( ) {
150- break ;
151- }
144+ let pred = predicate;
145+ // Constraint is implied by a coroutine's well-formedness.
146+ if self . infcx . tcx . sess . opts . unstable_opts . higher_ranked_assumptions
147+ && higher_ranked_assumptions. contains ( & pred)
148+ {
149+ return ;
150+ }
152151
153- if !tcx. recursion_limit ( ) . value_within_limit ( iteration) {
154- // This may actually be reachable. If so, we should convert
155- // this to a proper error/consider whether we should detect
156- // this somewhere else.
157- bug ! (
158- "unexpected overflowed when processing region obligations: {outlives_predicates:#?}"
159- ) ;
152+ let ty:: OutlivesPredicate ( k1, r2) = pred;
153+ match k1. kind ( ) {
154+ GenericArgKind :: Lifetime ( r1) => {
155+ let r1_vid = self . to_region_vid ( r1) ;
156+ let r2_vid = self . to_region_vid ( r2) ;
157+ self . add_outlives ( r1_vid, r2_vid, constraint_category) ;
160158 }
161159
162- let mut next_outlives_predicates = vec ! [ ] ;
163- for ( pred, constraint_category) in outlives_predicates {
164- // Constraint is implied by a coroutine's well-formedness.
165- if self . infcx . tcx . sess . opts . unstable_opts . higher_ranked_assumptions
166- && higher_ranked_assumptions. contains ( & pred)
167- {
168- continue ;
169- }
170-
171- let ty:: OutlivesPredicate ( k1, r2) = pred;
172- match k1. kind ( ) {
173- GenericArgKind :: Lifetime ( r1) => {
174- let r1_vid = self . to_region_vid ( r1) ;
175- let r2_vid = self . to_region_vid ( r2) ;
176- self . add_outlives ( r1_vid, r2_vid, constraint_category) ;
177- }
178-
179- GenericArgKind :: Type ( mut t1) => {
180- // Scraped constraints may have had inference vars.
181- t1 = self . infcx . resolve_vars_if_possible ( t1) ;
182-
183- // Normalize the type we receive from a `TypeOutlives` obligation
184- // in the new trait solver.
185- if infcx. next_trait_solver ( ) {
186- t1 = self . normalize_and_add_type_outlives_constraints (
187- ty:: Unnormalized :: new_wip ( t1) ,
188- & mut next_outlives_predicates,
189- ) ;
190- }
160+ GenericArgKind :: Type ( mut t1) => {
161+ // Scraped constraints may have had inference vars.
162+ t1 = self . infcx . resolve_vars_if_possible ( t1) ;
191163
192- let implicit_region_bound =
193- ty:: Region :: new_var ( tcx, universal_regions. implicit_region_bound ( ) ) ;
194- // we don't actually use this for anything, but
195- // the `TypeOutlives` code needs an origin.
196- let origin = SubregionOrigin :: RelateParamBound ( self . span , t1, None ) ;
197- TypeOutlives :: new (
198- & mut * self ,
199- tcx,
200- region_bound_pairs,
201- Some ( implicit_region_bound) ,
202- known_type_outlives_obligations,
203- )
204- . type_must_outlive (
205- origin,
206- t1,
207- r2,
208- constraint_category,
209- ) ;
210- }
211-
212- GenericArgKind :: Const ( _) => unreachable ! ( ) ,
213- }
164+ let implicit_region_bound =
165+ ty:: Region :: new_var ( tcx, universal_regions. implicit_region_bound ( ) ) ;
166+ // we don't actually use this for anything, but
167+ // the `TypeOutlives` code needs an origin.
168+ let origin = SubregionOrigin :: RelateParamBound ( self . span , t1, None ) ;
169+ TypeOutlives :: new (
170+ & mut * self ,
171+ tcx,
172+ region_bound_pairs,
173+ Some ( implicit_region_bound) ,
174+ known_type_outlives_obligations,
175+ )
176+ . type_must_outlive ( origin, t1, r2, constraint_category) ;
214177 }
215178
216- outlives_predicates = next_outlives_predicates ;
179+ GenericArgKind :: Const ( _ ) => unreachable ! ( ) ,
217180 }
218181 }
219182
@@ -279,32 +242,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
279242 debug ! ( "add_type_test(type_test={:?})" , type_test) ;
280243 self . constraints . type_tests . push ( type_test) ;
281244 }
282-
283- // FIXME(trait-refactor-initiative#260): This function should be
284- // removed.
285- fn normalize_and_add_type_outlives_constraints (
286- & self ,
287- ty : ty:: Unnormalized < ' tcx , Ty < ' tcx > > ,
288- next_outlives_predicates : & mut Vec < (
289- ty:: ArgOutlivesPredicate < ' tcx > ,
290- ConstraintCategory < ' tcx > ,
291- ) > ,
292- ) -> Ty < ' tcx > {
293- match self . infcx . fully_perform ( Normalize { value : ty } , self . span ) {
294- Ok ( TypeOpOutput { output : ty, constraints, .. } ) => {
295- // FIXME(higher_ranked_auto): What should we do with the assumptions here?
296- if let Some ( QueryRegionConstraints { constraints, assumptions : _ } ) = constraints {
297- next_outlives_predicates. extend ( constraints. iter ( ) . flat_map (
298- |QueryRegionConstraint { constraint, category, .. } | {
299- constraint. iter_outlives ( ) . map ( |outlives| ( outlives, * category) )
300- } ,
301- ) ) ;
302- }
303- ty
304- }
305- Err ( _) => ty. skip_norm_wip ( ) ,
306- }
307- }
308245}
309246
310247impl < ' a , ' b , ' tcx > TypeOutlivesDelegate < ' tcx > for & ' a mut ConstraintConversion < ' b , ' tcx > {
0 commit comments