@@ -254,13 +254,16 @@ fn associated_type_for_impl_trait_in_trait(
254254 tcx : TyCtxt < ' _ > ,
255255 opaque_ty_def_id : LocalDefId ,
256256) -> 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) ;
259263 assert_eq ! ( tcx. def_kind( trait_def_id) , DefKind :: Trait ) ;
260264
261265 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 ) ;
264267
265268 let local_def_id = trait_assoc_ty. def_id ( ) ;
266269 let def_id = local_def_id. to_def_id ( ) ;
@@ -282,7 +285,7 @@ fn associated_type_for_impl_trait_in_trait(
282285 container : ty:: TraitContainer ,
283286 fn_has_self_parameter : false ,
284287 opt_rpitit_info : Some ( ImplTraitInTraitData :: Trait {
285- fn_def_id,
288+ fn_def_id : fn_def_id . to_def_id ( ) ,
286289 opaque_def_id : opaque_ty_def_id. to_def_id ( ) ,
287290 } ) ,
288291 } ) ;
@@ -324,7 +327,7 @@ fn associated_type_for_impl_trait_in_trait(
324327 params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
325328
326329 ty:: Generics {
327- parent : Some ( trait_def_id) ,
330+ parent : Some ( trait_def_id. to_def_id ( ) ) ,
328331 parent_count,
329332 params,
330333 param_def_id_to_index,
@@ -335,7 +338,7 @@ fn associated_type_for_impl_trait_in_trait(
335338
336339 // There are no predicates for the synthesized associated type.
337340 trait_assoc_ty. explicit_predicates_of ( ty:: GenericPredicates {
338- parent : Some ( trait_def_id) ,
341+ parent : Some ( trait_def_id. to_def_id ( ) ) ,
339342 predicates : & [ ] ,
340343 } ) ;
341344
@@ -356,7 +359,6 @@ fn associated_type_for_impl_trait_in_impl(
356359 impl_fn_def_id : LocalDefId ,
357360) -> LocalDefId {
358361 let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
359- let impl_def_id = impl_local_def_id. to_def_id ( ) ;
360362
361363 // FIXME fix the span, we probably want the def_id of the return type of the function
362364 let span = tcx. def_span ( impl_fn_def_id) ;
@@ -402,7 +404,7 @@ fn associated_type_for_impl_trait_in_impl(
402404 let trait_assoc_parent_count = trait_assoc_generics. parent_count ;
403405 let mut params = trait_assoc_generics. params . clone ( ) ;
404406
405- let parent_generics = tcx. generics_of ( impl_def_id ) ;
407+ let parent_generics = tcx. generics_of ( impl_local_def_id . to_def_id ( ) ) ;
406408 let parent_count = parent_generics. parent_count + parent_generics. params . len ( ) ;
407409
408410 for param in & mut params {
@@ -413,7 +415,7 @@ fn associated_type_for_impl_trait_in_impl(
413415 params. iter ( ) . map ( |param| ( param. def_id , param. index ) ) . collect ( ) ;
414416
415417 ty:: Generics {
416- parent : Some ( impl_def_id ) ,
418+ parent : Some ( impl_local_def_id . to_def_id ( ) ) ,
417419 parent_count,
418420 params,
419421 param_def_id_to_index,
@@ -424,7 +426,7 @@ fn associated_type_for_impl_trait_in_impl(
424426
425427 // There are no predicates for the synthesized associated type.
426428 impl_assoc_ty. explicit_predicates_of ( ty:: GenericPredicates {
427- parent : Some ( impl_def_id ) ,
429+ parent : Some ( impl_local_def_id . to_def_id ( ) ) ,
428430 predicates : & [ ] ,
429431 } ) ;
430432
0 commit comments