@@ -15,7 +15,8 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
1515use rustc_middle:: middle:: privacy:: { self , Level } ;
1616use rustc_middle:: mir:: interpret:: { ConstAllocation , GlobalAlloc } ;
1717use rustc_middle:: query:: Providers ;
18- use rustc_middle:: ty:: { self , TyCtxt } ;
18+ use rustc_middle:: ty:: { self , ExistentialTraitRef , TyCtxt } ;
19+ use rustc_privacy:: DefIdVisitor ;
1920use rustc_session:: config:: CrateType ;
2021use rustc_target:: spec:: abi:: Abi ;
2122
@@ -271,13 +272,22 @@ impl<'tcx> ReachableContext<'tcx> {
271272 self . propagate_item ( Res :: Def ( self . tcx . def_kind ( def_id) , def_id) )
272273 }
273274 GlobalAlloc :: Function ( instance) => {
275+ // Manually visit to actually see the instance's `DefId`. Type visitors won't see it
274276 self . propagate_item ( Res :: Def (
275277 self . tcx . def_kind ( instance. def_id ( ) ) ,
276278 instance. def_id ( ) ,
277- ) )
278- // TODO: walk generic args
279+ ) ) ;
280+ self . visit ( instance. args ) ;
281+ }
282+ GlobalAlloc :: VTable ( ty, trait_ref) => {
283+ self . visit ( ty) ;
284+ // Manually visit to actually see the trait's `DefId`. Type visitors won't see it
285+ if let Some ( trait_ref) = trait_ref {
286+ let ExistentialTraitRef { def_id, args } = trait_ref. skip_binder ( ) ;
287+ self . visit_def_id ( def_id, "" , & "" ) ;
288+ self . visit ( args) ;
289+ }
279290 }
280- GlobalAlloc :: VTable ( ty, trait_ref) => todo ! ( "{ty:?}, {trait_ref:?}" ) ,
281291 GlobalAlloc :: Memory ( alloc) => self . propagate_from_alloc ( root, alloc) ,
282292 }
283293 }
@@ -303,6 +313,23 @@ impl<'tcx> ReachableContext<'tcx> {
303313 }
304314}
305315
316+ impl < ' tcx > DefIdVisitor < ' tcx > for ReachableContext < ' tcx > {
317+ type Result = ( ) ;
318+
319+ fn tcx ( & self ) -> TyCtxt < ' tcx > {
320+ self . tcx
321+ }
322+
323+ fn visit_def_id (
324+ & mut self ,
325+ def_id : DefId ,
326+ _kind : & str ,
327+ _descr : & dyn std:: fmt:: Display ,
328+ ) -> Self :: Result {
329+ self . propagate_item ( Res :: Def ( self . tcx . def_kind ( def_id) , def_id) )
330+ }
331+ }
332+
306333fn check_item < ' tcx > (
307334 tcx : TyCtxt < ' tcx > ,
308335 id : hir:: ItemId ,
0 commit comments