@@ -22,7 +22,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
2222 let item = tcx. hir ( ) . expect_item ( def_id. expect_local ( ) ) ;
2323 match item. kind {
2424 hir:: ItemKind :: Trait ( .., ref trait_item_refs) => {
25- if tcx. sess . opts . unstable_opts . lower_impl_trait_in_trait_to_assoc_ty {
25+ if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
2626 // We collect RPITITs for each trait method's return type and create a
2727 // corresponding associated item using associated_items_for_impl_trait_in_trait
2828 // query.
@@ -53,7 +53,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
5353 }
5454 }
5555 hir:: ItemKind :: Impl ( ref impl_) => {
56- if tcx. sess . opts . unstable_opts . lower_impl_trait_in_trait_to_assoc_ty {
56+ if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
5757 // We collect RPITITs for each trait method's return type, on the impl side too and
5858 // create a corresponding associated item using
5959 // associated_items_for_impl_trait_in_trait query.
@@ -301,9 +301,6 @@ fn associated_item_for_impl_trait_in_trait(
301301 // There are no inferred outlives for the synthesized associated type.
302302 trait_assoc_ty. inferred_outlives_of ( & [ ] ) ;
303303
304- // FIXME implement this.
305- trait_assoc_ty. explicit_item_bounds ( & [ ] ) ;
306-
307304 local_def_id
308305}
309306
@@ -315,11 +312,12 @@ fn impl_associated_item_for_impl_trait_in_trait(
315312 trait_assoc_def_id : LocalDefId ,
316313 impl_fn_def_id : LocalDefId ,
317314) -> LocalDefId {
318- let impl_def_id = tcx. local_parent ( impl_fn_def_id) ;
315+ let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
316+ let impl_def_id = impl_local_def_id. to_def_id ( ) ;
319317
320318 // FIXME fix the span, we probably want the def_id of the return type of the function
321319 let span = tcx. def_span ( impl_fn_def_id) ;
322- let impl_assoc_ty = tcx. at ( span) . create_def ( impl_def_id , DefPathData :: ImplTraitAssocTy ) ;
320+ let impl_assoc_ty = tcx. at ( span) . create_def ( impl_local_def_id , DefPathData :: ImplTraitAssocTy ) ;
323321
324322 let local_def_id = impl_assoc_ty. def_id ( ) ;
325323 let def_id = local_def_id. to_def_id ( ) ;
@@ -344,13 +342,53 @@ fn impl_associated_item_for_impl_trait_in_trait(
344342 fn_has_self_parameter : false ,
345343 } ) ;
346344
345+ // Copy param_env of the containing function. The synthesized associated type doesn't have
346+ // extra predicates to assume.
347+ impl_assoc_ty. param_env ( tcx. param_env ( impl_fn_def_id) ) ;
348+
347349 // Copy impl_defaultness of the containing function.
348350 impl_assoc_ty. impl_defaultness ( tcx. impl_defaultness ( impl_fn_def_id) ) ;
349351
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 ( ) ) ;
352+ // Copy generics_of the trait's associated item but the impl as the parent.
353+ impl_assoc_ty. generics_of ( {
354+ let trait_assoc_generics = tcx. generics_of ( trait_assoc_def_id) ;
355+ let trait_assoc_parent_count = trait_assoc_generics. parent_count ;
356+ let mut params = trait_assoc_generics. params . clone ( ) ;
357+
358+ let parent_generics = tcx. generics_of ( impl_def_id) ;
359+ let parent_count = parent_generics. parent_count + parent_generics. params . len ( ) ;
360+
361+ let mut impl_fn_params = tcx. generics_of ( impl_fn_def_id) . params . clone ( ) ;
362+
363+ for param in & mut params {
364+ param. index = param. index + parent_count as u32 + impl_fn_params. len ( ) as u32
365+ - trait_assoc_parent_count as u32 ;
366+ }
367+
368+ impl_fn_params. extend ( params) ;
369+ params = impl_fn_params;
370+
371+ let param_def_id_to_index =
372+ params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
373+
374+ ty:: Generics {
375+ parent : Some ( impl_def_id) ,
376+ parent_count,
377+ params,
378+ param_def_id_to_index,
379+ has_self : false ,
380+ has_late_bound_regions : trait_assoc_generics. has_late_bound_regions ,
381+ }
382+ } ) ;
383+
384+ // There are no predicates for the synthesized associated type.
385+ impl_assoc_ty. explicit_predicates_of ( ty:: GenericPredicates {
386+ parent : Some ( impl_def_id) ,
387+ predicates : & [ ] ,
388+ } ) ;
389+
390+ // There are no inferred outlives for the synthesized associated type.
391+ impl_assoc_ty. inferred_outlives_of ( & [ ] ) ;
354392
355393 local_def_id
356394}
0 commit comments