@@ -606,7 +606,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
606
606
. infcx
607
607
. shallow_resolve ( obligation. self_ty ( ) . no_bound_vars ( ) )
608
608
. expect ( "fn pointer should not capture bound vars from predicate" ) ;
609
- let sig = self_ty. fn_sig ( self . tcx ( ) ) ;
609
+ // FnDef signatures are not necessarily normalized
610
+ let Normalized { value : sig, obligations : mut nested } = normalize_with_depth (
611
+ self ,
612
+ obligation. param_env ,
613
+ obligation. cause . clone ( ) ,
614
+ obligation. recursion_depth + 1 ,
615
+ self_ty. fn_sig ( self . tcx ( ) ) ,
616
+ ) ;
617
+
610
618
let trait_ref = closure_trait_ref_and_return_type (
611
619
self . tcx ( ) ,
612
620
obligation. predicate . def_id ( ) ,
@@ -616,22 +624,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
616
624
)
617
625
. map_bound ( |( trait_ref, _) | trait_ref) ;
618
626
619
- let mut nested = self . confirm_poly_trait_refs ( obligation, trait_ref) ?;
627
+ nested. extend ( self . confirm_poly_trait_refs ( obligation, trait_ref) ?) ;
620
628
621
629
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
622
630
let cause = obligation. derived_cause ( BuiltinDerivedObligation ) ;
623
- let output_ty = self . infcx . replace_bound_vars_with_placeholders ( sig. output ( ) ) ;
624
- let output_ty = normalize_with_depth_to (
625
- self ,
626
- obligation. param_env ,
627
- cause. clone ( ) ,
628
- obligation. recursion_depth + 1 ,
629
- output_ty,
630
- & mut nested,
631
- ) ;
632
- let tr =
633
- ty:: Binder :: dummy ( self . tcx ( ) . at ( cause. span ) . mk_trait_ref ( LangItem :: Sized , [ output_ty] ) ) ;
634
- nested. push ( Obligation :: new ( self . infcx . tcx , cause, obligation. param_env , tr) ) ;
631
+ let predicate = sig
632
+ . output ( )
633
+ . map_bound ( |ty| self . tcx ( ) . at ( cause. span ) . mk_trait_ref ( LangItem :: Sized , [ ty] ) ) ;
634
+ nested. push ( Obligation :: new ( self . infcx . tcx , cause, obligation. param_env , predicate) ) ;
635
635
636
636
Ok ( ImplSourceFnPointerData { fn_ty : self_ty, nested } )
637
637
}
@@ -799,25 +799,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
799
799
expected_trait_ref : ty:: PolyTraitRef < ' tcx > ,
800
800
) -> Result < Vec < PredicateObligation < ' tcx > > , SelectionError < ' tcx > > {
801
801
let obligation_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
802
- // Normalize the obligation and expected trait refs together, because why not
803
- let Normalized { obligations : nested, value : ( obligation_trait_ref, expected_trait_ref) } =
804
- ensure_sufficient_stack ( || {
805
- normalize_with_depth (
806
- self ,
807
- obligation. param_env ,
808
- obligation. cause . clone ( ) ,
809
- obligation. recursion_depth + 1 ,
810
- ( obligation_trait_ref, expected_trait_ref) ,
811
- )
812
- } ) ;
813
-
814
802
self . infcx
815
803
. at ( & obligation. cause , obligation. param_env )
816
804
. sup ( obligation_trait_ref, expected_trait_ref)
817
- . map ( |InferOk { mut obligations, .. } | {
818
- obligations. extend ( nested) ;
819
- obligations
820
- } )
805
+ . map ( |InferOk { value : ( ) , obligations } | obligations)
821
806
. map_err ( |e| OutputTypeParameterMismatch ( expected_trait_ref, obligation_trait_ref, e) )
822
807
}
823
808
0 commit comments