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