1
+ use rustc_data_structures:: fx:: FxIndexSet ;
1
2
use rustc_hir as hir;
2
3
use rustc_hir:: def:: DefKind ;
3
4
use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId } ;
@@ -196,20 +197,26 @@ fn associated_types_for_impl_traits_in_associated_fn(
196
197
197
198
match tcx. def_kind ( parent_def_id) {
198
199
DefKind :: Trait => {
199
- struct RPITVisitor {
200
- rpits : Vec < LocalDefId > ,
200
+ struct RPITVisitor < ' tcx > {
201
+ rpits : FxIndexSet < LocalDefId > ,
202
+ tcx : TyCtxt < ' tcx > ,
201
203
}
202
204
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
+ }
207
214
}
208
215
intravisit:: walk_ty ( self , ty)
209
216
}
210
217
}
211
218
212
- let mut visitor = RPITVisitor { rpits : Vec :: new ( ) } ;
219
+ let mut visitor = RPITVisitor { tcx , rpits : FxIndexSet :: default ( ) } ;
213
220
214
221
if let Some ( output) = tcx. hir ( ) . get_fn_output ( fn_def_id) {
215
222
visitor. visit_fn_ret_ty ( output) ;
@@ -227,13 +234,9 @@ fn associated_types_for_impl_traits_in_associated_fn(
227
234
228
235
tcx. arena . alloc_from_iter (
229
236
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 ( )
237
240
} ,
238
241
) ,
239
242
)
@@ -355,7 +358,7 @@ fn associated_type_for_impl_trait_in_trait(
355
358
/// that inherits properties that we infer from the method and the associated type.
356
359
fn associated_type_for_impl_trait_in_impl (
357
360
tcx : TyCtxt < ' _ > ,
358
- trait_assoc_def_id : LocalDefId ,
361
+ trait_assoc_def_id : DefId ,
359
362
impl_fn_def_id : LocalDefId ,
360
363
) -> LocalDefId {
361
364
let impl_local_def_id = tcx. local_parent ( impl_fn_def_id) ;
@@ -380,7 +383,7 @@ fn associated_type_for_impl_trait_in_impl(
380
383
name : kw:: Empty ,
381
384
kind : ty:: AssocKind :: Type ,
382
385
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) ,
384
387
container : ty:: ImplContainer ,
385
388
fn_has_self_parameter : false ,
386
389
opt_rpitit_info : Some ( ImplTraitInTraitData :: Impl { fn_def_id : impl_fn_def_id. to_def_id ( ) } ) ,
0 commit comments