@@ -5,13 +5,14 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
55use rustc_infer:: infer:: outlives:: env:: RegionBoundPairs ;
66use rustc_infer:: infer:: region_constraints:: GenericKind ;
77use rustc_infer:: infer:: { InferCtxt , outlives} ;
8+ use rustc_infer:: traits:: ScrubbedTraitError ;
89use rustc_middle:: mir:: ConstraintCategory ;
910use rustc_middle:: traits:: ObligationCause ;
1011use rustc_middle:: traits:: query:: OutlivesBound ;
1112use rustc_middle:: ty:: { self , RegionVid , Ty , TypeVisitableExt } ;
1213use rustc_span:: { ErrorGuaranteed , Span } ;
13- use rustc_trait_selection:: error_reporting :: InferCtxtErrorExt ;
14- use rustc_trait_selection:: solve :: deeply_normalize ;
14+ use rustc_trait_selection:: solve :: NoSolution ;
15+ use rustc_trait_selection:: traits :: query :: type_op :: custom :: CustomTypeOp ;
1516use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOp } ;
1617use tracing:: { debug, instrument} ;
1718use type_op:: TypeOpOutput ;
@@ -229,24 +230,14 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
229230 let mut constraints = vec ! [ ] ;
230231 let mut known_type_outlives_obligations = vec ! [ ] ;
231232 for bound in param_env. caller_bounds ( ) {
232- let Some ( mut outlives) = bound. as_type_outlives_clause ( ) else { continue } ;
233-
234- // In the new solver, normalize the type-outlives obligation assumptions.
235- if self . infcx . next_trait_solver ( ) {
236- match deeply_normalize (
237- self . infcx . at ( & ObligationCause :: misc ( span, defining_ty_def_id) , param_env) ,
233+ if let Some ( outlives) = bound. as_type_outlives_clause ( ) {
234+ self . normalize_and_push_type_outlives_obligation (
238235 outlives,
239- ) {
240- Ok ( normalized_outlives) => {
241- outlives = normalized_outlives;
242- }
243- Err ( e) => {
244- self . infcx . err_ctxt ( ) . report_fulfillment_errors ( e) ;
245- }
246- }
247- }
248-
249- known_type_outlives_obligations. push ( outlives) ;
236+ span,
237+ & mut known_type_outlives_obligations,
238+ & mut constraints,
239+ ) ;
240+ } ;
250241 }
251242
252243 let unnormalized_input_output_tys = self
@@ -356,6 +347,44 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
356347 }
357348 }
358349
350+ fn normalize_and_push_type_outlives_obligation (
351+ & self ,
352+ mut outlives : ty:: PolyTypeOutlivesPredicate < ' tcx > ,
353+ span : Span ,
354+ known_type_outlives_obligations : & mut Vec < ty:: PolyTypeOutlivesPredicate < ' tcx > > ,
355+ constraints : & mut Vec < & QueryRegionConstraints < ' tcx > > ,
356+ ) {
357+ // In the new solver, normalize the type-outlives obligation assumptions.
358+ if self . infcx . next_trait_solver ( ) {
359+ let Ok ( TypeOpOutput {
360+ output : normalized_outlives,
361+ constraints : constraints_normalize,
362+ error_info : _,
363+ } ) = CustomTypeOp :: new (
364+ |ocx| {
365+ ocx. deeply_normalize (
366+ & ObligationCause :: dummy_with_span ( span) ,
367+ self . param_env ,
368+ outlives,
369+ )
370+ . map_err ( |_: Vec < ScrubbedTraitError < ' tcx > > | NoSolution )
371+ } ,
372+ "normalize type outlives obligation" ,
373+ )
374+ . fully_perform ( self . infcx , span)
375+ else {
376+ self . infcx . dcx ( ) . delayed_bug ( format ! ( "could not normalize {outlives:?}" ) ) ;
377+ return ;
378+ } ;
379+ outlives = normalized_outlives;
380+ if let Some ( c) = constraints_normalize {
381+ constraints. push ( c) ;
382+ }
383+ }
384+
385+ known_type_outlives_obligations. push ( outlives) ;
386+ }
387+
359388 /// Update the type of a single local, which should represent
360389 /// either the return type of the MIR or one of its arguments. At
361390 /// the same time, compute and add any implied bounds that come
0 commit comments