@@ -313,11 +313,12 @@ fn impl_associated_item_for_impl_trait_in_trait(
313
313
trait_assoc_def_id : LocalDefId ,
314
314
impl_fn_def_id : LocalDefId ,
315
315
) -> LocalDefId {
316
- let impl_def_id = tcx. local_parent ( impl_fn_def_id) ;
316
+ let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
317
+ let impl_def_id = impl_local_def_id. to_def_id ( ) ;
317
318
318
319
// FIXME fix the span, we probably want the def_id of the return type of the function
319
320
let span = tcx. def_span ( impl_fn_def_id) ;
320
- let impl_assoc_ty = tcx. at ( span) . create_def ( impl_def_id , DefPathData :: ImplTraitAssocTy ) ;
321
+ let impl_assoc_ty = tcx. at ( span) . create_def ( impl_local_def_id , DefPathData :: ImplTraitAssocTy ) ;
321
322
322
323
let local_def_id = impl_assoc_ty. def_id ( ) ;
323
324
let def_id = local_def_id. to_def_id ( ) ;
@@ -349,10 +350,37 @@ fn impl_associated_item_for_impl_trait_in_trait(
349
350
// Copy impl_defaultness of the containing function.
350
351
impl_assoc_ty. impl_defaultness ( tcx. impl_defaultness ( impl_fn_def_id) ) ;
351
352
352
- // Copy generics_of the trait's associated item.
353
- // FIXME: This is not correct, in particular the parent is going to be wrong. So we would need
354
- // to copy from trait_assoc_def_id and adjust things.
355
- impl_assoc_ty. generics_of ( tcx. generics_of ( trait_assoc_def_id) . clone ( ) ) ;
353
+ // Copy generics_of the trait's associated item but the impl as the parent.
354
+ impl_assoc_ty. generics_of ( {
355
+ let trait_assoc_generics = tcx. generics_of ( trait_assoc_def_id) ;
356
+ let trait_assoc_parent_count = trait_assoc_generics. parent_count ;
357
+ let mut params = trait_assoc_generics. params . clone ( ) ;
358
+
359
+ let parent_generics = tcx. generics_of ( impl_def_id) ;
360
+ let parent_count = parent_generics. parent_count + parent_generics. params . len ( ) ;
361
+
362
+ let mut impl_fn_params = tcx. generics_of ( impl_fn_def_id) . params . clone ( ) ;
363
+
364
+ for param in & mut params {
365
+ param. index = param. index + parent_count as u32 + impl_fn_params. len ( ) as u32
366
+ - trait_assoc_parent_count as u32 ;
367
+ }
368
+
369
+ impl_fn_params. extend ( params) ;
370
+ params = impl_fn_params;
371
+
372
+ let param_def_id_to_index =
373
+ params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
374
+
375
+ ty:: Generics {
376
+ parent : Some ( impl_def_id) ,
377
+ parent_count,
378
+ params,
379
+ param_def_id_to_index,
380
+ has_self : false ,
381
+ has_late_bound_regions : trait_assoc_generics. has_late_bound_regions ,
382
+ }
383
+ } ) ;
356
384
357
385
local_def_id
358
386
}
0 commit comments