@@ -51,7 +51,7 @@ pub(crate) fn compare_impl_method<'tcx>(
51
51
return ;
52
52
}
53
53
54
- if let Err ( _) = compare_number_of_generics ( tcx, impl_m, impl_m_span , trait_m, trait_item_span) {
54
+ if let Err ( _) = compare_number_of_generics ( tcx, impl_m, trait_m, trait_item_span) {
55
55
return ;
56
56
}
57
57
@@ -352,6 +352,10 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
352
352
let impl_trait_ref = tcx. impl_trait_ref ( impl_m. impl_container ( tcx) . unwrap ( ) ) . unwrap ( ) ;
353
353
let param_env = tcx. param_env ( def_id) ;
354
354
355
+ // First, check a few of the same thing as `compare_impl_method`, just so we don't ICE during substitutions later.
356
+ compare_number_of_generics ( tcx, impl_m, trait_m, tcx. hir ( ) . span_if_local ( impl_m. def_id ) ) ?;
357
+ compare_generic_param_kinds ( tcx, impl_m, trait_m) ?;
358
+
355
359
let trait_to_impl_substs = impl_trait_ref. substs ;
356
360
357
361
let impl_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_m. def_id . expect_local ( ) ) ;
@@ -376,6 +380,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
376
380
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
377
381
let ocx = ObligationCtxt :: new ( infcx) ;
378
382
383
+ // Normalize the impl signature with fresh variables for lifetime inference.
379
384
let norm_cause = ObligationCause :: misc ( return_span, impl_m_hir_id) ;
380
385
let impl_sig = ocx. normalize (
381
386
norm_cause. clone ( ) ,
@@ -388,6 +393,10 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
388
393
) ;
389
394
let impl_return_ty = impl_sig. output ( ) ;
390
395
396
+ // Normalize the trait signature with liberated bound vars, passing it through
397
+ // the ImplTraitInTraitCollector, which gathers all of the RPITITs and replaces
398
+ // them with inference variables.
399
+ // We will use these inference variables to collect the hidden types of RPITITs.
391
400
let mut collector = ImplTraitInTraitCollector :: new ( & ocx, return_span, param_env, impl_m_hir_id) ;
392
401
let unnormalized_trait_sig = tcx
393
402
. liberate_late_bound_regions (
@@ -922,7 +931,6 @@ fn compare_self_type<'tcx>(
922
931
fn compare_number_of_generics < ' tcx > (
923
932
tcx : TyCtxt < ' tcx > ,
924
933
impl_ : & ty:: AssocItem ,
925
- _impl_span : Span ,
926
934
trait_ : & ty:: AssocItem ,
927
935
trait_span : Option < Span > ,
928
936
) -> Result < ( ) , ErrorGuaranteed > {
@@ -1489,7 +1497,7 @@ pub(crate) fn compare_ty_impl<'tcx>(
1489
1497
debug ! ( "compare_impl_type(impl_trait_ref={:?})" , impl_trait_ref) ;
1490
1498
1491
1499
let _: Result < ( ) , ErrorGuaranteed > = ( || {
1492
- compare_number_of_generics ( tcx, impl_ty, impl_ty_span , trait_ty, trait_item_span) ?;
1500
+ compare_number_of_generics ( tcx, impl_ty, trait_ty, trait_item_span) ?;
1493
1501
1494
1502
compare_generic_param_kinds ( tcx, impl_ty, trait_ty) ?;
1495
1503
0 commit comments