@@ -553,23 +553,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
553
553
)
554
554
. map_bound ( |( trait_ref, _) | trait_ref) ;
555
555
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 } )
573
558
}
574
559
575
560
fn confirm_trait_alias_candidate (
@@ -616,26 +601,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
616
601
debug ! ( ?obligation, ?generator_def_id, ?substs, "confirm_generator_candidate" ) ;
617
602
618
603
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
- } ) ;
628
604
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" ) ;
637
607
638
- Ok ( ImplSourceGeneratorData { generator_def_id, substs, nested : obligations } )
608
+ Ok ( ImplSourceGeneratorData { generator_def_id, substs, nested } )
639
609
}
640
610
641
611
#[ instrument( skip( self ) , level = "debug" ) ]
@@ -657,52 +627,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
657
627
_ => bug ! ( "closure candidate for non-closure {:?}" , obligation) ,
658
628
} ;
659
629
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
-
672
630
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) ?;
683
632
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" ) ;
693
634
694
635
// FIXME: Chalk
695
636
696
637
if !self . tcx ( ) . sess . opts . debugging_opts . chalk {
697
- obligations . push ( Obligation :: new (
638
+ nested . push ( Obligation :: new (
698
639
obligation. cause . clone ( ) ,
699
640
obligation. param_env ,
700
641
ty:: Binder :: dummy ( ty:: PredicateKind :: ClosureKind ( closure_def_id, substs, kind) )
701
642
. to_predicate ( self . tcx ( ) ) ,
702
643
) ) ;
703
644
}
704
645
705
- Ok ( ImplSourceClosureData { closure_def_id, substs, nested : obligations } )
646
+ Ok ( ImplSourceClosureData { closure_def_id, substs, nested } )
706
647
}
707
648
708
649
/// In the case of closure types and fn pointers,
@@ -733,15 +674,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
733
674
#[ instrument( skip( self ) , level = "trace" ) ]
734
675
fn confirm_poly_trait_refs (
735
676
& 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 > ,
739
678
expected_trait_ref : ty:: PolyTraitRef < ' tcx > ,
740
679
) -> 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
+
741
695
self . infcx
742
- . at ( & obligation_cause , obligation_param_env )
696
+ . at ( & obligation . cause , obligation . param_env )
743
697
. sup ( obligation_trait_ref, expected_trait_ref)
744
- . map ( |InferOk { obligations, .. } | obligations)
698
+ . map ( |InferOk { mut obligations, .. } | {
699
+ obligations. extend ( nested) ;
700
+ obligations
701
+ } )
745
702
. map_err ( |e| OutputTypeParameterMismatch ( expected_trait_ref, obligation_trait_ref, e) )
746
703
}
747
704
0 commit comments