@@ -16,7 +16,8 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
16
16
use rustc_middle:: middle:: privacy:: { self , Level } ;
17
17
use rustc_middle:: mir:: interpret:: { ConstAllocation , GlobalAlloc } ;
18
18
use rustc_middle:: query:: Providers ;
19
- use rustc_middle:: ty:: { self , TyCtxt } ;
19
+ use rustc_middle:: ty:: { self , ExistentialTraitRef , TyCtxt } ;
20
+ use rustc_privacy:: DefIdVisitor ;
20
21
use rustc_session:: config:: CrateType ;
21
22
use rustc_target:: spec:: abi:: Abi ;
22
23
@@ -272,13 +273,22 @@ impl<'tcx> ReachableContext<'tcx> {
272
273
self . propagate_item ( Res :: Def ( self . tcx . def_kind ( def_id) , def_id) )
273
274
}
274
275
GlobalAlloc :: Function ( instance) => {
276
+ // Manually visit to actually see the instance's `DefId`. Type visitors won't see it
275
277
self . propagate_item ( Res :: Def (
276
278
self . tcx . def_kind ( instance. def_id ( ) ) ,
277
279
instance. def_id ( ) ,
278
- ) )
279
- // TODO: walk generic args
280
+ ) ) ;
281
+ self . visit ( instance. args ) ;
282
+ }
283
+ GlobalAlloc :: VTable ( ty, trait_ref) => {
284
+ self . visit ( ty) ;
285
+ // Manually visit to actually see the trait's `DefId`. Type visitors won't see it
286
+ if let Some ( trait_ref) = trait_ref {
287
+ let ExistentialTraitRef { def_id, args } = trait_ref. skip_binder ( ) ;
288
+ self . visit_def_id ( def_id, "" , & "" ) ;
289
+ self . visit ( args) ;
290
+ }
280
291
}
281
- GlobalAlloc :: VTable ( ty, trait_ref) => todo ! ( "{ty:?}, {trait_ref:?}" ) ,
282
292
GlobalAlloc :: Memory ( alloc) => self . propagate_from_alloc ( alloc) ,
283
293
}
284
294
}
@@ -318,6 +328,23 @@ impl<'tcx> ReachableContext<'tcx> {
318
328
}
319
329
}
320
330
331
+ impl < ' tcx > DefIdVisitor < ' tcx > for ReachableContext < ' tcx > {
332
+ type Result = ( ) ;
333
+
334
+ fn tcx ( & self ) -> TyCtxt < ' tcx > {
335
+ self . tcx
336
+ }
337
+
338
+ fn visit_def_id (
339
+ & mut self ,
340
+ def_id : DefId ,
341
+ _kind : & str ,
342
+ _descr : & dyn std:: fmt:: Display ,
343
+ ) -> Self :: Result {
344
+ self . propagate_item ( Res :: Def ( self . tcx . def_kind ( def_id) , def_id) )
345
+ }
346
+ }
347
+
321
348
fn check_item < ' tcx > (
322
349
tcx : TyCtxt < ' tcx > ,
323
350
id : hir:: ItemId ,
0 commit comments