@@ -19,6 +19,7 @@ use super::PredicateObligation;
1919use super :: SelectionContext ;
2020use super :: SelectionError ;
2121use super :: VtableClosureData ;
22+ use super :: VtableFnPointerData ;
2223use super :: VtableImplData ;
2324use super :: util;
2425
@@ -158,7 +159,7 @@ enum ProjectionTyCandidate<'tcx> {
158159 Closure ( VtableClosureData < ' tcx , PredicateObligation < ' tcx > > ) ,
159160
160161 // fn pointer return type
161- FnPointer ( Ty < ' tcx > ) ,
162+ FnPointer ( VtableFnPointerData < ' tcx , PredicateObligation < ' tcx > > ) ,
162163}
163164
164165struct ProjectionTyCandidateSet < ' tcx > {
@@ -218,10 +219,7 @@ fn project_and_unify_type<'cx, 'gcx, 'tcx>(
218219 obligation. cause . clone ( ) ,
219220 obligation. recursion_depth ) {
220221 Some ( n) => n,
221- None => {
222- consider_unification_despite_ambiguity ( selcx, obligation) ;
223- return Ok ( None ) ;
224- }
222+ None => return Ok ( None ) ,
225223 } ;
226224
227225 debug ! ( "project_and_unify_type: normalized_ty={:?} obligations={:?}" ,
@@ -240,59 +238,6 @@ fn project_and_unify_type<'cx, 'gcx, 'tcx>(
240238 }
241239}
242240
243- fn consider_unification_despite_ambiguity < ' cx , ' gcx , ' tcx > (
244- selcx : & mut SelectionContext < ' cx , ' gcx , ' tcx > ,
245- obligation : & ProjectionObligation < ' tcx > )
246- {
247- debug ! ( "consider_unification_despite_ambiguity(obligation={:?})" ,
248- obligation) ;
249-
250- let def_id = obligation. predicate . projection_ty . trait_ref . def_id ;
251- match selcx. tcx ( ) . lang_items . fn_trait_kind ( def_id) {
252- Some ( _) => { }
253- None => { return ; }
254- }
255-
256- let infcx = selcx. infcx ( ) ;
257- let self_ty = obligation. predicate . projection_ty . trait_ref . self_ty ( ) ;
258- let self_ty = infcx. shallow_resolve ( self_ty) ;
259- debug ! ( "consider_unification_despite_ambiguity: self_ty.sty={:?}" ,
260- self_ty. sty) ;
261- match self_ty. sty {
262- ty:: TyClosure ( closure_def_id, substs) => {
263- let closure_typer = selcx. closure_typer ( ) ;
264- let closure_type = closure_typer. closure_type ( closure_def_id, substs) ;
265- let ty:: Binder ( ( _, ret_type) ) =
266- infcx. tcx . closure_trait_ref_and_return_type ( def_id,
267- self_ty,
268- & closure_type. sig ,
269- util:: TupleArgumentsFlag :: No ) ;
270- // We don't have to normalize the return type here - this is only
271- // reached for TyClosure: Fn inputs where the closure kind is
272- // still unknown, which should only occur in typeck where the
273- // closure type is already normalized.
274- let ( ret_type, _) =
275- infcx. replace_late_bound_regions_with_fresh_var (
276- obligation. cause . span ,
277- infer:: AssocTypeProjection ( obligation. predicate . projection_ty . item_name ) ,
278- & ty:: Binder ( ret_type) ) ;
279-
280- debug ! ( "consider_unification_despite_ambiguity: ret_type={:?}" ,
281- ret_type) ;
282- let origin = TypeOrigin :: RelateOutputImplTypes ( obligation. cause . span ) ;
283- let obligation_ty = obligation. predicate . ty ;
284- match infcx. eq_types ( true , origin, obligation_ty, ret_type) {
285- Ok ( InferOk { obligations, .. } ) => {
286- // FIXME(#32730) propagate obligations
287- assert ! ( obligations. is_empty( ) ) ;
288- }
289- Err ( _) => { /* ignore errors */ }
290- }
291- }
292- _ => { }
293- }
294- }
295-
296241/// Normalizes any associated type projections in `value`, replacing
297242/// them with a fully resolved type where possible. The return value
298243/// combines the normalized result and any additional obligations that
@@ -929,9 +874,9 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
929874 candidate_set. vec . push (
930875 ProjectionTyCandidate :: Closure ( data) ) ;
931876 }
932- super :: VtableFnPointer ( fn_type ) => {
877+ super :: VtableFnPointer ( data ) => {
933878 candidate_set. vec . push (
934- ProjectionTyCandidate :: FnPointer ( fn_type ) ) ;
879+ ProjectionTyCandidate :: FnPointer ( data ) ) ;
935880 }
936881 super :: VtableParam ( ..) => {
937882 // This case tell us nothing about the value of an
@@ -997,19 +942,22 @@ fn confirm_candidate<'cx, 'gcx, 'tcx>(
997942 confirm_closure_candidate ( selcx, obligation, closure_vtable)
998943 }
999944
1000- ProjectionTyCandidate :: FnPointer ( fn_type ) => {
1001- confirm_fn_pointer_candidate ( selcx, obligation, fn_type )
945+ ProjectionTyCandidate :: FnPointer ( fn_pointer_vtable ) => {
946+ confirm_fn_pointer_candidate ( selcx, obligation, fn_pointer_vtable )
1002947 }
1003948 }
1004949}
1005950
1006951fn confirm_fn_pointer_candidate < ' cx , ' gcx , ' tcx > (
1007952 selcx : & mut SelectionContext < ' cx , ' gcx , ' tcx > ,
1008953 obligation : & ProjectionTyObligation < ' tcx > ,
1009- fn_type : Ty < ' tcx > )
954+ fn_pointer_vtable : VtableFnPointerData < ' tcx , PredicateObligation < ' tcx > > )
1010955 -> ( Ty < ' tcx > , Vec < PredicateObligation < ' tcx > > )
1011956{
1012- let fn_type = selcx. infcx ( ) . shallow_resolve ( fn_type) ;
957+ // FIXME(#32730) propagate obligations (fn pointer vtable nested obligations ONLY come from
958+ // unification in inference)
959+ assert ! ( fn_pointer_vtable. nested. is_empty( ) ) ;
960+ let fn_type = selcx. infcx ( ) . shallow_resolve ( fn_pointer_vtable. fn_ty ) ;
1013961 let sig = fn_type. fn_sig ( ) ;
1014962 confirm_callable_candidate ( selcx, obligation, sig, util:: TupleArgumentsFlag :: Yes )
1015963}
0 commit comments