@@ -211,13 +211,15 @@ impl<'tcx> ReachableContext<'tcx> {
211211 if !self . any_library {
212212 // If we are building an executable, only explicitly extern
213213 // types need to be exported.
214- if let Node :: Item ( item) = * node {
215- let reachable = if let hir:: ItemKind :: Fn ( ref sig, ..) = item. kind {
216- sig. header . abi != Abi :: Rust
217- } else {
218- false
219- } ;
220- let codegen_attrs = self . tcx . codegen_fn_attrs ( item. def_id ) ;
214+ if let Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Fn ( sig, ..) , def_id, .. } )
215+ | Node :: ImplItem ( hir:: ImplItem {
216+ kind : hir:: ImplItemKind :: Fn ( sig, ..) ,
217+ def_id,
218+ ..
219+ } ) = * node
220+ {
221+ let reachable = sig. header . abi != Abi :: Rust ;
222+ let codegen_attrs = self . tcx . codegen_fn_attrs ( * def_id) ;
221223 let is_extern = codegen_attrs. contains_extern_indicator ( ) ;
222224 let std_internal =
223225 codegen_attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) ;
@@ -335,17 +337,23 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx> {
335337 worklist : & ' a mut Vec < LocalDefId > ,
336338}
337339
338- impl < ' a , ' tcx > ItemLikeVisitor < ' tcx > for CollectPrivateImplItemsVisitor < ' a , ' tcx > {
339- fn visit_item ( & mut self , item : & hir :: Item < ' _ > ) {
340+ impl CollectPrivateImplItemsVisitor < ' _ , ' _ > {
341+ fn push_to_worklist_if_has_custom_linkage ( & mut self , def_id : LocalDefId ) {
340342 // Anything which has custom linkage gets thrown on the worklist no
341343 // matter where it is in the crate, along with "special std symbols"
342344 // which are currently akin to allocator symbols.
343- let codegen_attrs = self . tcx . codegen_fn_attrs ( item . def_id ) ;
345+ let codegen_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
344346 if codegen_attrs. contains_extern_indicator ( )
345347 || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL )
346348 {
347- self . worklist . push ( item . def_id ) ;
349+ self . worklist . push ( def_id) ;
348350 }
351+ }
352+ }
353+
354+ impl < ' a , ' tcx > ItemLikeVisitor < ' tcx > for CollectPrivateImplItemsVisitor < ' a , ' tcx > {
355+ fn visit_item ( & mut self , item : & hir:: Item < ' _ > ) {
356+ self . push_to_worklist_if_has_custom_linkage ( item. def_id ) ;
349357
350358 // We need only trait impls here, not inherent impls, and only non-exported ones
351359 if let hir:: ItemKind :: Impl ( hir:: Impl { of_trait : Some ( ref trait_ref) , ref items, .. } ) =
@@ -375,8 +383,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
375383
376384 fn visit_trait_item ( & mut self , _trait_item : & hir:: TraitItem < ' _ > ) { }
377385
378- fn visit_impl_item ( & mut self , _impl_item : & hir:: ImplItem < ' _ > ) {
379- // processed in visit_item above
386+ fn visit_impl_item ( & mut self , impl_item : & hir:: ImplItem < ' _ > ) {
387+ self . push_to_worklist_if_has_custom_linkage ( impl_item . def_id ) ;
380388 }
381389
382390 fn visit_foreign_item ( & mut self , _foreign_item : & hir:: ForeignItem < ' _ > ) {
0 commit comments