@@ -149,6 +149,7 @@ fn compare_predicate_entailment<'tcx>(
149
149
impl_trait_ref : ty:: TraitRef < ' tcx > ,
150
150
) -> Result < ( ) , ErrorGuaranteed > {
151
151
let trait_to_impl_substs = impl_trait_ref. substs ;
152
+ debug ! ( ?trait_to_impl_substs) ;
152
153
153
154
// This node-id should be used for the `body_id` field on each
154
155
// `ObligationCause` (and the `FnCtxt`).
@@ -173,7 +174,7 @@ fn compare_predicate_entailment<'tcx>(
173
174
// Create mapping from trait to placeholder.
174
175
let trait_to_placeholder_substs =
175
176
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) ;
177
178
178
179
let impl_m_generics = tcx. generics_of ( impl_m. def_id ) ;
179
180
let trait_m_generics = tcx. generics_of ( trait_m. def_id ) ;
@@ -191,7 +192,7 @@ fn compare_predicate_entailment<'tcx>(
191
192
let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
192
193
let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) ;
193
194
194
- debug ! ( "compare_impl_method: impl_bounds={:?}" , hybrid_preds) ;
195
+ debug ! ( "impl_bounds={:?}" , hybrid_preds) ;
195
196
196
197
// This is the only tricky bit of the new way we check implementation methods
197
198
// We need to build a set of predicates where only the method-level bounds
@@ -218,7 +219,7 @@ fn compare_predicate_entailment<'tcx>(
218
219
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
219
220
let ocx = ObligationCtxt :: new ( infcx) ;
220
221
221
- debug ! ( "compare_impl_method: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
222
+ debug ! ( "caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
222
223
223
224
let mut selcx = traits:: SelectionContext :: new ( & infcx) ;
224
225
let impl_m_own_bounds = impl_m_predicates. instantiate_own ( tcx, impl_to_placeholder_substs) ;
@@ -258,18 +259,17 @@ fn compare_predicate_entailment<'tcx>(
258
259
259
260
let mut wf_tys = FxHashSet :: default ( ) ;
260
261
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) ;
266
265
267
266
let norm_cause = ObligationCause :: misc ( impl_m_span, impl_m_hir_id) ;
268
267
let impl_sig = ocx. normalize ( norm_cause. clone ( ) , param_env, impl_sig) ;
269
268
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) ;
271
270
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) ;
273
273
let trait_sig = tcx. liberate_late_bound_regions ( impl_m. def_id , trait_sig) ;
274
274
275
275
// Next, add all inputs and output as well-formed tys. Importantly,
@@ -281,8 +281,7 @@ fn compare_predicate_entailment<'tcx>(
281
281
// as we don't normalize during implied bounds computation.
282
282
wf_tys. extend ( trait_sig. inputs_and_output . iter ( ) ) ;
283
283
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) ;
286
285
287
286
// FIXME: We'd want to keep more accurate spans than "the method signature" when
288
287
// processing the comparison between the trait and impl fn, but we sadly lose them
@@ -431,6 +430,7 @@ fn compare_predicate_entailment<'tcx>(
431
430
Ok ( ( ) )
432
431
}
433
432
433
+ #[ instrument( level = "debug" , skip( tcx) , ret) ]
434
434
pub fn collect_trait_impl_trait_tys < ' tcx > (
435
435
tcx : TyCtxt < ' tcx > ,
436
436
def_id : DefId ,
@@ -464,25 +464,23 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
464
464
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
465
465
let ocx = ObligationCtxt :: new ( infcx) ;
466
466
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
+
467
471
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) ;
477
473
let impl_return_ty = impl_sig. output ( ) ;
478
474
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
+
479
481
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
+
486
484
let trait_sig = ocx. normalize ( norm_cause. clone ( ) , param_env, unnormalized_trait_sig) ;
487
485
let trait_return_ty = trait_sig. output ( ) ;
488
486
@@ -704,15 +702,11 @@ fn check_region_bounds_on_impl_item<'tcx>(
704
702
trait_generics : & ty:: Generics ,
705
703
impl_generics : & ty:: Generics ,
706
704
) -> 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 ;
716
710
717
711
// Must have same number of early-bound lifetime parameters.
718
712
// Unfortunately, if the user screws up the bounds, then this
0 commit comments