@@ -5,13 +5,11 @@ use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelega
55use rustc_infer:: infer:: region_constraints:: { GenericKind , VerifyBound } ;
66use rustc_infer:: infer:: { self , InferCtxt , SubregionOrigin } ;
77use rustc_middle:: mir:: { ClosureOutlivesSubject , ClosureRegionRequirements , ConstraintCategory } ;
8+ use rustc_middle:: traits:: query:: NoSolution ;
89use rustc_middle:: traits:: ObligationCause ;
9- use rustc_middle:: ty:: GenericArgKind ;
10- use rustc_middle:: ty:: { self , TyCtxt } ;
11- use rustc_middle:: ty:: { TypeFoldable , TypeVisitableExt } ;
10+ use rustc_middle:: ty:: { self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
1211use rustc_span:: { Span , DUMMY_SP } ;
1312use rustc_trait_selection:: solve:: deeply_normalize;
14- use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
1513use rustc_trait_selection:: traits:: query:: type_op:: custom:: CustomTypeOp ;
1614use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
1715
@@ -146,7 +144,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
146144 let ConstraintConversion {
147145 tcx,
148146 infcx,
149- param_env,
150147 region_bound_pairs,
151148 implicit_region_bound,
152149 known_type_outlives_obligations,
@@ -178,43 +175,10 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
178175 // Normalize the type we receive from a `TypeOutlives` obligation
179176 // in the new trait solver.
180177 if infcx. next_trait_solver ( ) {
181- let result = CustomTypeOp :: new (
182- |ocx| {
183- match deeply_normalize (
184- ocx. infcx . at (
185- & ObligationCause :: dummy_with_span ( self . span ) ,
186- param_env,
187- ) ,
188- t1,
189- ) {
190- Ok ( normalized_ty) => {
191- t1 = normalized_ty;
192- }
193- Err ( e) => {
194- infcx. err_ctxt ( ) . report_fulfillment_errors ( e) ;
195- }
196- }
197-
198- Ok ( ( ) )
199- } ,
200- "normalize type outlives obligation" ,
201- )
202- . fully_perform ( infcx, self . span ) ;
203-
204- match result {
205- Ok ( TypeOpOutput { output : ( ) , constraints, .. } ) => {
206- if let Some ( constraints) = constraints {
207- assert ! (
208- constraints. member_constraints. is_empty( ) ,
209- "no member constraints expected from normalizing: {:#?}" ,
210- constraints. member_constraints
211- ) ;
212- next_outlives_predicates
213- . extend ( constraints. outlives . iter ( ) . copied ( ) ) ;
214- }
215- }
216- Err ( _) => { }
217- }
178+ t1 = self . normalize_and_add_type_outlives_constraints (
179+ t1,
180+ & mut next_outlives_predicates,
181+ ) ;
218182 }
219183
220184 // we don't actually use this for anything, but
@@ -306,6 +270,42 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
306270 debug ! ( "add_type_test(type_test={:?})" , type_test) ;
307271 self . constraints . type_tests . push ( type_test) ;
308272 }
273+
274+ fn normalize_and_add_type_outlives_constraints (
275+ & self ,
276+ ty : Ty < ' tcx > ,
277+ next_outlives_predicates : & mut Vec < (
278+ ty:: OutlivesPredicate < ty:: GenericArg < ' tcx > , ty:: Region < ' tcx > > ,
279+ ConstraintCategory < ' tcx > ,
280+ ) > ,
281+ ) -> Ty < ' tcx > {
282+ let result = CustomTypeOp :: new (
283+ |ocx| {
284+ deeply_normalize (
285+ ocx. infcx . at ( & ObligationCause :: dummy_with_span ( self . span ) , self . param_env ) ,
286+ ty,
287+ )
288+ . map_err ( |_| NoSolution )
289+ } ,
290+ "normalize type outlives obligation" ,
291+ )
292+ . fully_perform ( self . infcx , self . span ) ;
293+
294+ match result {
295+ Ok ( TypeOpOutput { output : ty, constraints, .. } ) => {
296+ if let Some ( constraints) = constraints {
297+ assert ! (
298+ constraints. member_constraints. is_empty( ) ,
299+ "no member constraints expected from normalizing: {:#?}" ,
300+ constraints. member_constraints
301+ ) ;
302+ next_outlives_predicates. extend ( constraints. outlives . iter ( ) . copied ( ) ) ;
303+ }
304+ ty
305+ }
306+ Err ( _) => ty,
307+ }
308+ }
309309}
310310
311311impl < ' a , ' b , ' tcx > TypeOutlivesDelegate < ' tcx > for & ' a mut ConstraintConversion < ' b , ' tcx > {
0 commit comments