@@ -149,6 +149,7 @@ fn compare_predicate_entailment<'tcx>(
149149 impl_trait_ref : ty:: TraitRef < ' tcx > ,
150150) -> Result < ( ) , ErrorGuaranteed > {
151151 let trait_to_impl_substs = impl_trait_ref. substs ;
152+ debug ! ( ?trait_to_impl_substs) ;
152153
153154 // This node-id should be used for the `body_id` field on each
154155 // `ObligationCause` (and the `FnCtxt`).
@@ -173,7 +174,7 @@ fn compare_predicate_entailment<'tcx>(
173174 // Create mapping from trait to placeholder.
174175 let trait_to_placeholder_substs =
175176 impl_to_placeholder_substs. rebase_onto ( tcx, impl_m. container_id ( tcx) , trait_to_impl_substs) ;
176- debug ! ( "compare_impl_method: trait_to_placeholder_substs={:?}" , trait_to_placeholder_substs) ;
177+ debug ! ( ? trait_to_placeholder_substs) ;
177178
178179 let impl_m_generics = tcx. generics_of ( impl_m. def_id ) ;
179180 let trait_m_generics = tcx. generics_of ( trait_m. def_id ) ;
@@ -191,7 +192,7 @@ fn compare_predicate_entailment<'tcx>(
191192 let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
192193 let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) ;
193194
194- debug ! ( "compare_impl_method: impl_bounds={:?}" , hybrid_preds) ;
195+ debug ! ( "impl_bounds={:?}" , hybrid_preds) ;
195196
196197 // This is the only tricky bit of the new way we check implementation methods
197198 // We need to build a set of predicates where only the method-level bounds
@@ -218,7 +219,7 @@ fn compare_predicate_entailment<'tcx>(
218219 let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
219220 let ocx = ObligationCtxt :: new ( infcx) ;
220221
221- debug ! ( "compare_impl_method: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
222+ debug ! ( "caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
222223
223224 let mut selcx = traits:: SelectionContext :: new ( & infcx) ;
224225 let impl_m_own_bounds = impl_m_predicates. instantiate_own ( tcx, impl_to_placeholder_substs) ;
@@ -258,18 +259,17 @@ fn compare_predicate_entailment<'tcx>(
258259
259260 let mut wf_tys = FxHashSet :: default ( ) ;
260261
261- let impl_sig = infcx. replace_bound_vars_with_fresh_vars (
262- impl_m_span,
263- infer:: HigherRankedType ,
264- tcx. fn_sig ( impl_m. def_id ) ,
265- ) ;
262+ let impl_sig = tcx. mk_fn_def ( impl_m. def_id , impl_to_placeholder_substs) . fn_sig ( tcx) ;
263+ let impl_sig =
264+ infcx. replace_bound_vars_with_fresh_vars ( impl_m_span, infer:: HigherRankedType , impl_sig) ;
266265
267266 let norm_cause = ObligationCause :: misc ( impl_m_span, impl_m_hir_id) ;
268267 let impl_sig = ocx. normalize ( norm_cause. clone ( ) , param_env, impl_sig) ;
269268 let impl_fty = tcx. mk_fn_ptr ( ty:: Binder :: dummy ( impl_sig) ) ;
270- debug ! ( "compare_impl_method: impl_fty={:?}" , impl_fty) ;
269+ debug ! ( ? impl_fty) ;
271270
272- let trait_sig = tcx. bound_fn_sig ( trait_m. def_id ) . subst ( tcx, trait_to_placeholder_substs) ;
271+ let trait_sig = tcx. type_of ( trait_m. def_id ) . fn_sig ( tcx) ;
272+ let trait_sig = ty:: EarlyBinder ( trait_sig) . subst ( tcx, trait_to_placeholder_substs) ;
273273 let trait_sig = tcx. liberate_late_bound_regions ( impl_m. def_id , trait_sig) ;
274274
275275 // Next, add all inputs and output as well-formed tys. Importantly,
@@ -281,8 +281,7 @@ fn compare_predicate_entailment<'tcx>(
281281 // as we don't normalize during implied bounds computation.
282282 wf_tys. extend ( trait_sig. inputs_and_output . iter ( ) ) ;
283283 let trait_fty = tcx. mk_fn_ptr ( ty:: Binder :: dummy ( trait_sig) ) ;
284-
285- debug ! ( "compare_impl_method: trait_fty={:?}" , trait_fty) ;
284+ debug ! ( ?trait_fty) ;
286285
287286 // FIXME: We'd want to keep more accurate spans than "the method signature" when
288287 // processing the comparison between the trait and impl fn, but we sadly lose them
@@ -431,6 +430,7 @@ fn compare_predicate_entailment<'tcx>(
431430 Ok ( ( ) )
432431}
433432
433+ #[ instrument( level = "debug" , skip( tcx) , ret) ]
434434pub fn collect_trait_impl_trait_tys < ' tcx > (
435435 tcx : TyCtxt < ' tcx > ,
436436 def_id : DefId ,
@@ -464,25 +464,23 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
464464 let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
465465 let ocx = ObligationCtxt :: new ( infcx) ;
466466
467+ let impl_sig = tcx. mk_fn_def ( impl_m. def_id , impl_to_placeholder_substs) . fn_sig ( tcx) ;
468+ let impl_sig =
469+ infcx. replace_bound_vars_with_fresh_vars ( return_span, infer:: HigherRankedType , impl_sig) ;
470+
467471 let norm_cause = ObligationCause :: misc ( return_span, impl_m_hir_id) ;
468- let impl_sig = ocx. normalize (
469- norm_cause. clone ( ) ,
470- param_env,
471- infcx. replace_bound_vars_with_fresh_vars (
472- return_span,
473- infer:: HigherRankedType ,
474- tcx. fn_sig ( impl_m. def_id ) ,
475- ) ,
476- ) ;
472+ let impl_sig = ocx. normalize ( norm_cause. clone ( ) , param_env, impl_sig) ;
477473 let impl_return_ty = impl_sig. output ( ) ;
478474
475+ let unnormalized_trait_sig = tcx. type_of ( trait_m. def_id ) . fn_sig ( tcx) ;
476+ let unnormalized_trait_sig =
477+ ty:: EarlyBinder ( unnormalized_trait_sig) . subst ( tcx, trait_to_placeholder_substs) ;
478+ let unnormalized_trait_sig =
479+ tcx. liberate_late_bound_regions ( impl_m. def_id , unnormalized_trait_sig) ;
480+
479481 let mut collector = ImplTraitInTraitCollector :: new ( & ocx, return_span, param_env, impl_m_hir_id) ;
480- let unnormalized_trait_sig = tcx
481- . liberate_late_bound_regions (
482- impl_m. def_id ,
483- tcx. bound_fn_sig ( trait_m. def_id ) . subst ( tcx, trait_to_placeholder_substs) ,
484- )
485- . fold_with ( & mut collector) ;
482+ let unnormalized_trait_sig = unnormalized_trait_sig. fold_with ( & mut collector) ;
483+
486484 let trait_sig = ocx. normalize ( norm_cause. clone ( ) , param_env, unnormalized_trait_sig) ;
487485 let trait_return_ty = trait_sig. output ( ) ;
488486
@@ -704,15 +702,11 @@ fn check_region_bounds_on_impl_item<'tcx>(
704702 trait_generics : & ty:: Generics ,
705703 impl_generics : & ty:: Generics ,
706704) -> Result < ( ) , ErrorGuaranteed > {
707- let trait_params = trait_generics. own_counts ( ) . lifetimes ;
708- let impl_params = impl_generics. own_counts ( ) . lifetimes ;
709-
710- debug ! (
711- "check_region_bounds_on_impl_item: \
712- trait_generics={:?} \
713- impl_generics={:?}",
714- trait_generics, impl_generics
715- ) ;
705+ // For backwards compatibility reasons, we can only check that we have the correct amount
706+ // of early-bound lifetimes. The user is allowed to introduce as many late-bound lifetime
707+ // as they want.
708+ let trait_params = trait_generics. own_counts ( ) . early_lifetimes ;
709+ let impl_params = impl_generics. own_counts ( ) . early_lifetimes ;
716710
717711 // Must have same number of early-bound lifetime parameters.
718712 // Unfortunately, if the user screws up the bounds, then this
0 commit comments