@@ -317,6 +317,58 @@ fn do_normalize_predicates<'tcx>(
317317 }
318318}
319319
320+ // A temporay hack. Don't use this.
321+ // See `deeply_normalize_param_env_or_error`.
322+ #[ instrument( level = "debug" , skip( tcx, elaborated_env) ) ]
323+ fn do_deeply_normalize_predicates < ' tcx > (
324+ tcx : TyCtxt < ' tcx > ,
325+ cause : ObligationCause < ' tcx > ,
326+ elaborated_env : ty:: ParamEnv < ' tcx > ,
327+ predicates : Vec < ty:: Clause < ' tcx > > ,
328+ ) -> Result < Vec < ty:: Clause < ' tcx > > , ErrorGuaranteed > {
329+ let span = cause. span ;
330+ let infcx = tcx
331+ . infer_ctxt ( )
332+ . with_next_trait_solver ( true )
333+ . ignoring_regions ( )
334+ . build ( TypingMode :: non_body_analysis ( ) ) ;
335+ let predicates = match crate :: solve:: deeply_normalize :: < _ , FulfillmentError < ' tcx > > (
336+ infcx. at ( & cause, elaborated_env) ,
337+ predicates,
338+ ) {
339+ Ok ( predicates) => predicates,
340+ Err ( errors) => {
341+ let reported = infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
342+ return Err ( reported) ;
343+ }
344+ } ;
345+
346+ debug ! ( "do_normalize_predicates: normalized predicates = {:?}" , predicates) ;
347+
348+ // The next solver doesn't ignore region constraints so we do it manually.
349+ drop ( infcx. take_registered_region_obligations ( ) ) ;
350+ drop ( infcx. take_registered_region_assumptions ( ) ) ;
351+ drop ( infcx. take_and_reset_region_constraints ( ) ) ;
352+ let errors = infcx. resolve_regions ( cause. body_id , elaborated_env, [ ] ) ;
353+ if !errors. is_empty ( ) {
354+ tcx. dcx ( ) . span_delayed_bug (
355+ span,
356+ format ! ( "failed region resolution while normalizing {elaborated_env:?}: {errors:?}" ) ,
357+ ) ;
358+ }
359+
360+ match infcx. fully_resolve ( predicates) {
361+ Ok ( predicates) => Ok ( predicates) ,
362+ Err ( fixup_err) => {
363+ span_bug ! (
364+ span,
365+ "inference variables in normalized parameter environment: {}" ,
366+ fixup_err
367+ )
368+ }
369+ }
370+ }
371+
320372// FIXME: this is gonna need to be removed ...
321373/// Normalizes the parameter environment, reporting errors if they occur.
322374#[ instrument( level = "debug" , skip( tcx) ) ]
@@ -477,6 +529,66 @@ pub fn normalize_param_env_or_error<'tcx>(
477529 ty:: ParamEnv :: new ( tcx. mk_clauses ( & predicates) )
478530}
479531
532+ // FIXME(-Zhigher-ranked-assumptions): this is a hack to walk around the fact that we don't support
533+ // placeholder assumptions right now.
534+ // We should remove this once we have proper support for implied bounds on binders.
535+ /// Deeply normalize the param env using the next solver.
536+ #[ instrument( level = "debug" , skip( tcx) ) ]
537+ pub fn deeply_normalize_param_env_or_error < ' tcx > (
538+ tcx : TyCtxt < ' tcx > ,
539+ unnormalized_env : ty:: ParamEnv < ' tcx > ,
540+ cause : ObligationCause < ' tcx > ,
541+ ) -> ty:: ParamEnv < ' tcx > {
542+ let mut predicates: Vec < _ > =
543+ util:: elaborate ( tcx, unnormalized_env. caller_bounds ( ) . into_iter ( ) ) . collect ( ) ;
544+
545+ debug ! ( "normalize_param_env_or_error: elaborated-predicates={:?}" , predicates) ;
546+
547+ let elaborated_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & predicates) ) ;
548+ if !elaborated_env. has_aliases ( ) {
549+ return elaborated_env;
550+ }
551+
552+ let outlives_predicates: Vec < _ > = predicates
553+ . extract_if ( .., |predicate| {
554+ matches ! ( predicate. kind( ) . skip_binder( ) , ty:: ClauseKind :: TypeOutlives ( ..) )
555+ } )
556+ . collect ( ) ;
557+
558+ debug ! (
559+ "normalize_param_env_or_error: predicates=(non-outlives={:?}, outlives={:?})" ,
560+ predicates, outlives_predicates
561+ ) ;
562+ let Ok ( non_outlives_predicates) =
563+ do_deeply_normalize_predicates ( tcx, cause. clone ( ) , elaborated_env, predicates)
564+ else {
565+ // An unnormalized env is better than nothing.
566+ debug ! ( "normalize_param_env_or_error: errored resolving non-outlives predicates" ) ;
567+ return elaborated_env;
568+ } ;
569+
570+ debug ! ( "normalize_param_env_or_error: non-outlives predicates={:?}" , non_outlives_predicates) ;
571+
572+ // Not sure whether it is better to include the unnormalized TypeOutlives predicates
573+ // here. I believe they should not matter, because we are ignoring TypeOutlives param-env
574+ // predicates here anyway. Keeping them here anyway because it seems safer.
575+ let outlives_env = non_outlives_predicates. iter ( ) . chain ( & outlives_predicates) . cloned ( ) ;
576+ let outlives_env = ty:: ParamEnv :: new ( tcx. mk_clauses_from_iter ( outlives_env) ) ;
577+ let Ok ( outlives_predicates) =
578+ do_deeply_normalize_predicates ( tcx, cause, outlives_env, outlives_predicates)
579+ else {
580+ // An unnormalized env is better than nothing.
581+ debug ! ( "normalize_param_env_or_error: errored resolving outlives predicates" ) ;
582+ return elaborated_env;
583+ } ;
584+ debug ! ( "normalize_param_env_or_error: outlives predicates={:?}" , outlives_predicates) ;
585+
586+ let mut predicates = non_outlives_predicates;
587+ predicates. extend ( outlives_predicates) ;
588+ debug ! ( "normalize_param_env_or_error: final predicates={:?}" , predicates) ;
589+ ty:: ParamEnv :: new ( tcx. mk_clauses ( & predicates) )
590+ }
591+
480592#[ derive( Debug ) ]
481593pub enum EvaluateConstErr {
482594 /// The constant being evaluated was either a generic parameter or inference variable, *or*,
0 commit comments