@@ -16,7 +16,8 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
1616use rustc_middle:: middle:: privacy:: { self , Level } ;
1717use rustc_middle:: mir:: interpret:: { ConstAllocation , GlobalAlloc } ;
1818use rustc_middle:: query:: Providers ;
19- use rustc_middle:: ty:: { self , TyCtxt } ;
19+ use rustc_middle:: ty:: { self , ExistentialTraitRef , TyCtxt } ;
20+ use rustc_privacy:: DefIdVisitor ;
2021use rustc_session:: config:: CrateType ;
2122use rustc_target:: spec:: abi:: Abi ;
2223
@@ -272,13 +273,22 @@ impl<'tcx> ReachableContext<'tcx> {
272273 self . propagate_item ( Res :: Def ( self . tcx . def_kind ( def_id) , def_id) )
273274 }
274275 GlobalAlloc :: Function ( instance) => {
276+ // Manually visit to actually see the instance's `DefId`. Type visitors won't see it
275277 self . propagate_item ( Res :: Def (
276278 self . tcx . def_kind ( instance. def_id ( ) ) ,
277279 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+ }
280291 }
281- GlobalAlloc :: VTable ( ty, trait_ref) => todo ! ( "{ty:?}, {trait_ref:?}" ) ,
282292 GlobalAlloc :: Memory ( alloc) => self . propagate_from_alloc ( alloc) ,
283293 }
284294 }
@@ -318,6 +328,23 @@ impl<'tcx> ReachableContext<'tcx> {
318328 }
319329}
320330
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+
321348fn check_item < ' tcx > (
322349 tcx : TyCtxt < ' tcx > ,
323350 id : hir:: ItemId ,
0 commit comments