1+ use rustc_data_structures:: fx:: FxIndexSet ;
12use rustc_hir as hir;
23use rustc_hir:: def:: DefKind ;
34use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId } ;
@@ -196,20 +197,26 @@ fn associated_types_for_impl_traits_in_associated_fn(
196197
197198 match tcx. def_kind ( parent_def_id) {
198199 DefKind :: Trait => {
199- struct RPITVisitor {
200- rpits : Vec < LocalDefId > ,
200+ struct RPITVisitor < ' tcx > {
201+ rpits : FxIndexSet < LocalDefId > ,
202+ tcx : TyCtxt < ' tcx > ,
201203 }
202204
203- impl < ' v > Visitor < ' v > for RPITVisitor {
204- fn visit_ty ( & mut self , ty : & ' v hir:: Ty < ' v > ) {
205- if let hir:: TyKind :: OpaqueDef ( item_id, _, _) = ty. kind {
206- self . rpits . push ( item_id. owner_id . def_id )
205+ impl < ' tcx > Visitor < ' tcx > for RPITVisitor < ' tcx > {
206+ fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty < ' tcx > ) {
207+ if let hir:: TyKind :: OpaqueDef ( item_id, _, _) = ty. kind
208+ && self . rpits . insert ( item_id. owner_id . def_id )
209+ {
210+ let opaque_item = self . tcx . hir ( ) . expect_item ( item_id. owner_id . def_id ) . expect_opaque_ty ( ) ;
211+ for bound in opaque_item. bounds {
212+ intravisit:: walk_param_bound ( self , bound) ;
213+ }
207214 }
208215 intravisit:: walk_ty ( self , ty)
209216 }
210217 }
211218
212- let mut visitor = RPITVisitor { rpits : Vec :: new ( ) } ;
219+ let mut visitor = RPITVisitor { tcx , rpits : FxIndexSet :: default ( ) } ;
213220
214221 if let Some ( output) = tcx. hir ( ) . get_fn_output ( fn_def_id) {
215222 visitor. visit_fn_ret_ty ( output) ;
@@ -227,13 +234,9 @@ fn associated_types_for_impl_traits_in_associated_fn(
227234
228235 tcx. arena . alloc_from_iter (
229236 tcx. associated_types_for_impl_traits_in_associated_fn ( trait_fn_def_id) . iter ( ) . map (
230- move |trait_assoc_def_id| {
231- associated_type_for_impl_trait_in_impl (
232- tcx,
233- trait_assoc_def_id. expect_local ( ) ,
234- fn_def_id,
235- )
236- . to_def_id ( )
237+ move |& trait_assoc_def_id| {
238+ associated_type_for_impl_trait_in_impl ( tcx, trait_assoc_def_id, fn_def_id)
239+ . to_def_id ( )
237240 } ,
238241 ) ,
239242 )
@@ -355,7 +358,7 @@ fn associated_type_for_impl_trait_in_trait(
355358/// that inherits properties that we infer from the method and the associated type.
356359fn associated_type_for_impl_trait_in_impl (
357360 tcx : TyCtxt < ' _ > ,
358- trait_assoc_def_id : LocalDefId ,
361+ trait_assoc_def_id : DefId ,
359362 impl_fn_def_id : LocalDefId ,
360363) -> LocalDefId {
361364 let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
@@ -380,7 +383,7 @@ fn associated_type_for_impl_trait_in_impl(
380383 name : kw:: Empty ,
381384 kind : ty:: AssocKind :: Type ,
382385 def_id,
383- trait_item_def_id : Some ( trait_assoc_def_id. to_def_id ( ) ) ,
386+ trait_item_def_id : Some ( trait_assoc_def_id) ,
384387 container : ty:: ImplContainer ,
385388 fn_has_self_parameter : false ,
386389 opt_rpitit_info : Some ( ImplTraitInTraitData :: Impl { fn_def_id : impl_fn_def_id. to_def_id ( ) } ) ,
0 commit comments