@@ -553,23 +553,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
553553 )
554554 . map_bound ( |( trait_ref, _) | trait_ref) ;
555555
556- let Normalized { value : trait_ref, mut obligations } = ensure_sufficient_stack ( || {
557- normalize_with_depth (
558- self ,
559- obligation. param_env ,
560- obligation. cause . clone ( ) ,
561- obligation. recursion_depth + 1 ,
562- trait_ref,
563- )
564- } ) ;
565-
566- obligations. extend ( self . confirm_poly_trait_refs (
567- obligation. cause . clone ( ) ,
568- obligation. param_env ,
569- obligation. predicate . to_poly_trait_ref ( ) ,
570- trait_ref,
571- ) ?) ;
572- Ok ( ImplSourceFnPointerData { fn_ty : self_ty, nested : obligations } )
556+ let nested = self . confirm_poly_trait_refs ( obligation, trait_ref) ?;
557+ Ok ( ImplSourceFnPointerData { fn_ty : self_ty, nested } )
573558 }
574559
575560 fn confirm_trait_alias_candidate (
@@ -616,26 +601,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
616601 debug ! ( ?obligation, ?generator_def_id, ?substs, "confirm_generator_candidate" ) ;
617602
618603 let trait_ref = self . generator_trait_ref_unnormalized ( obligation, substs) ;
619- let Normalized { value : trait_ref, mut obligations } = ensure_sufficient_stack ( || {
620- normalize_with_depth (
621- self ,
622- obligation. param_env ,
623- obligation. cause . clone ( ) ,
624- obligation. recursion_depth + 1 ,
625- trait_ref,
626- )
627- } ) ;
628604
629- debug ! ( ?trait_ref, ?obligations, "generator candidate obligations" ) ;
630-
631- obligations. extend ( self . confirm_poly_trait_refs (
632- obligation. cause . clone ( ) ,
633- obligation. param_env ,
634- obligation. predicate . to_poly_trait_ref ( ) ,
635- trait_ref,
636- ) ?) ;
605+ let nested = self . confirm_poly_trait_refs ( obligation, trait_ref) ?;
606+ debug ! ( ?trait_ref, ?nested, "generator candidate obligations" ) ;
637607
638- Ok ( ImplSourceGeneratorData { generator_def_id, substs, nested : obligations } )
608+ Ok ( ImplSourceGeneratorData { generator_def_id, substs, nested } )
639609 }
640610
641611 #[ instrument( skip( self ) , level = "debug" ) ]
@@ -657,52 +627,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
657627 _ => bug ! ( "closure candidate for non-closure {:?}" , obligation) ,
658628 } ;
659629
660- let obligation_predicate = obligation. predicate ;
661- let Normalized { value : obligation_predicate, mut obligations } =
662- ensure_sufficient_stack ( || {
663- normalize_with_depth (
664- self ,
665- obligation. param_env ,
666- obligation. cause . clone ( ) ,
667- obligation. recursion_depth + 1 ,
668- obligation_predicate,
669- )
670- } ) ;
671-
672630 let trait_ref = self . closure_trait_ref_unnormalized ( obligation, substs) ;
673- let Normalized { value : trait_ref, obligations : trait_ref_obligations } =
674- ensure_sufficient_stack ( || {
675- normalize_with_depth (
676- self ,
677- obligation. param_env ,
678- obligation. cause . clone ( ) ,
679- obligation. recursion_depth + 1 ,
680- trait_ref,
681- )
682- } ) ;
631+ let mut nested = self . confirm_poly_trait_refs ( obligation, trait_ref) ?;
683632
684- debug ! ( ?closure_def_id, ?trait_ref, ?obligations, "confirm closure candidate obligations" ) ;
685-
686- obligations. extend ( trait_ref_obligations) ;
687- obligations. extend ( self . confirm_poly_trait_refs (
688- obligation. cause . clone ( ) ,
689- obligation. param_env ,
690- obligation_predicate. to_poly_trait_ref ( ) ,
691- trait_ref,
692- ) ?) ;
633+ debug ! ( ?closure_def_id, ?trait_ref, ?nested, "confirm closure candidate obligations" ) ;
693634
694635 // FIXME: Chalk
695636
696637 if !self . tcx ( ) . sess . opts . debugging_opts . chalk {
697- obligations . push ( Obligation :: new (
638+ nested . push ( Obligation :: new (
698639 obligation. cause . clone ( ) ,
699640 obligation. param_env ,
700641 ty:: Binder :: dummy ( ty:: PredicateKind :: ClosureKind ( closure_def_id, substs, kind) )
701642 . to_predicate ( self . tcx ( ) ) ,
702643 ) ) ;
703644 }
704645
705- Ok ( ImplSourceClosureData { closure_def_id, substs, nested : obligations } )
646+ Ok ( ImplSourceClosureData { closure_def_id, substs, nested } )
706647 }
707648
708649 /// In the case of closure types and fn pointers,
@@ -733,15 +674,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
733674 #[ instrument( skip( self ) , level = "trace" ) ]
734675 fn confirm_poly_trait_refs (
735676 & mut self ,
736- obligation_cause : ObligationCause < ' tcx > ,
737- obligation_param_env : ty:: ParamEnv < ' tcx > ,
738- obligation_trait_ref : ty:: PolyTraitRef < ' tcx > ,
677+ obligation : & TraitObligation < ' tcx > ,
739678 expected_trait_ref : ty:: PolyTraitRef < ' tcx > ,
740679 ) -> Result < Vec < PredicateObligation < ' tcx > > , SelectionError < ' tcx > > {
680+ let obligation_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
681+ // Normalize the obligation and expected trait refs together, because why not
682+ let Normalized { obligations : nested, value : ( obligation_trait_ref, expected_trait_ref) } =
683+ ensure_sufficient_stack ( || {
684+ self . infcx . commit_unconditionally ( |_| {
685+ normalize_with_depth (
686+ self ,
687+ obligation. param_env ,
688+ obligation. cause . clone ( ) ,
689+ obligation. recursion_depth + 1 ,
690+ ( obligation_trait_ref, expected_trait_ref) ,
691+ )
692+ } )
693+ } ) ;
694+
741695 self . infcx
742- . at ( & obligation_cause , obligation_param_env )
696+ . at ( & obligation . cause , obligation . param_env )
743697 . sup ( obligation_trait_ref, expected_trait_ref)
744- . map ( |InferOk { obligations, .. } | obligations)
698+ . map ( |InferOk { mut obligations, .. } | {
699+ obligations. extend ( nested) ;
700+ obligations
701+ } )
745702 . map_err ( |e| OutputTypeParameterMismatch ( expected_trait_ref, obligation_trait_ref, e) )
746703 }
747704
0 commit comments