@@ -22,7 +22,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
22
22
let item = tcx. hir ( ) . expect_item ( def_id. expect_local ( ) ) ;
23
23
match item. kind {
24
24
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 ( ) {
26
26
// We collect RPITITs for each trait method's return type and create a
27
27
// corresponding associated item using associated_items_for_impl_trait_in_trait
28
28
// query.
@@ -53,7 +53,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
53
53
}
54
54
}
55
55
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 ( ) {
57
57
// We collect RPITITs for each trait method's return type, on the impl side too and
58
58
// create a corresponding associated item using
59
59
// associated_items_for_impl_trait_in_trait query.
@@ -301,9 +301,6 @@ fn associated_item_for_impl_trait_in_trait(
301
301
// There are no inferred outlives for the synthesized associated type.
302
302
trait_assoc_ty. inferred_outlives_of ( & [ ] ) ;
303
303
304
- // FIXME implement this.
305
- trait_assoc_ty. explicit_item_bounds ( & [ ] ) ;
306
-
307
304
local_def_id
308
305
}
309
306
@@ -315,11 +312,12 @@ fn impl_associated_item_for_impl_trait_in_trait(
315
312
trait_assoc_def_id : LocalDefId ,
316
313
impl_fn_def_id : LocalDefId ,
317
314
) -> 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 ( ) ;
319
317
320
318
// FIXME fix the span, we probably want the def_id of the return type of the function
321
319
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 ) ;
323
321
324
322
let local_def_id = impl_assoc_ty. def_id ( ) ;
325
323
let def_id = local_def_id. to_def_id ( ) ;
@@ -344,13 +342,53 @@ fn impl_associated_item_for_impl_trait_in_trait(
344
342
fn_has_self_parameter : false ,
345
343
} ) ;
346
344
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
+
347
349
// Copy impl_defaultness of the containing function.
348
350
impl_assoc_ty. impl_defaultness ( tcx. impl_defaultness ( impl_fn_def_id) ) ;
349
351
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 ( & [ ] ) ;
354
392
355
393
local_def_id
356
394
}
0 commit comments