@@ -254,13 +254,16 @@ fn associated_type_for_impl_trait_in_trait(
254
254
tcx : TyCtxt < ' _ > ,
255
255
opaque_ty_def_id : LocalDefId ,
256
256
) -> LocalDefId {
257
- let fn_def_id = tcx. impl_trait_in_trait_parent_fn ( opaque_ty_def_id. to_def_id ( ) ) ;
258
- let trait_def_id = tcx. parent ( fn_def_id) ;
257
+ let ( hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) | hir:: OpaqueTyOrigin :: AsyncFn ( fn_def_id) ) =
258
+ tcx. hir ( ) . expect_item ( opaque_ty_def_id) . expect_opaque_ty ( ) . origin
259
+ else {
260
+ bug ! ( "expected opaque for {opaque_ty_def_id:?}" ) ;
261
+ } ;
262
+ let trait_def_id = tcx. local_parent ( fn_def_id) ;
259
263
assert_eq ! ( tcx. def_kind( trait_def_id) , DefKind :: Trait ) ;
260
264
261
265
let span = tcx. def_span ( opaque_ty_def_id) ;
262
- let trait_assoc_ty =
263
- tcx. at ( span) . create_def ( trait_def_id. expect_local ( ) , DefPathData :: ImplTraitAssocTy ) ;
266
+ let trait_assoc_ty = tcx. at ( span) . create_def ( trait_def_id, DefPathData :: ImplTraitAssocTy ) ;
264
267
265
268
let local_def_id = trait_assoc_ty. def_id ( ) ;
266
269
let def_id = local_def_id. to_def_id ( ) ;
@@ -282,7 +285,7 @@ fn associated_type_for_impl_trait_in_trait(
282
285
container : ty:: TraitContainer ,
283
286
fn_has_self_parameter : false ,
284
287
opt_rpitit_info : Some ( ImplTraitInTraitData :: Trait {
285
- fn_def_id,
288
+ fn_def_id : fn_def_id . to_def_id ( ) ,
286
289
opaque_def_id : opaque_ty_def_id. to_def_id ( ) ,
287
290
} ) ,
288
291
} ) ;
@@ -324,7 +327,7 @@ fn associated_type_for_impl_trait_in_trait(
324
327
params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
325
328
326
329
ty:: Generics {
327
- parent : Some ( trait_def_id) ,
330
+ parent : Some ( trait_def_id. to_def_id ( ) ) ,
328
331
parent_count,
329
332
params,
330
333
param_def_id_to_index,
@@ -335,7 +338,7 @@ fn associated_type_for_impl_trait_in_trait(
335
338
336
339
// There are no predicates for the synthesized associated type.
337
340
trait_assoc_ty. explicit_predicates_of ( ty:: GenericPredicates {
338
- parent : Some ( trait_def_id) ,
341
+ parent : Some ( trait_def_id. to_def_id ( ) ) ,
339
342
predicates : & [ ] ,
340
343
} ) ;
341
344
@@ -356,7 +359,6 @@ fn associated_type_for_impl_trait_in_impl(
356
359
impl_fn_def_id : LocalDefId ,
357
360
) -> LocalDefId {
358
361
let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
359
- let impl_def_id = impl_local_def_id. to_def_id ( ) ;
360
362
361
363
// FIXME fix the span, we probably want the def_id of the return type of the function
362
364
let span = tcx. def_span ( impl_fn_def_id) ;
@@ -402,7 +404,7 @@ fn associated_type_for_impl_trait_in_impl(
402
404
let trait_assoc_parent_count = trait_assoc_generics. parent_count ;
403
405
let mut params = trait_assoc_generics. params . clone ( ) ;
404
406
405
- let parent_generics = tcx. generics_of ( impl_def_id ) ;
407
+ let parent_generics = tcx. generics_of ( impl_local_def_id . to_def_id ( ) ) ;
406
408
let parent_count = parent_generics. parent_count + parent_generics. params . len ( ) ;
407
409
408
410
for param in & mut params {
@@ -413,7 +415,7 @@ fn associated_type_for_impl_trait_in_impl(
413
415
params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
414
416
415
417
ty:: Generics {
416
- parent : Some ( impl_def_id ) ,
418
+ parent : Some ( impl_local_def_id . to_def_id ( ) ) ,
417
419
parent_count,
418
420
params,
419
421
param_def_id_to_index,
@@ -424,7 +426,7 @@ fn associated_type_for_impl_trait_in_impl(
424
426
425
427
// There are no predicates for the synthesized associated type.
426
428
impl_assoc_ty. explicit_predicates_of ( ty:: GenericPredicates {
427
- parent : Some ( impl_def_id ) ,
429
+ parent : Some ( impl_local_def_id . to_def_id ( ) ) ,
428
430
predicates : & [ ] ,
429
431
} ) ;
430
432
0 commit comments