@@ -427,8 +427,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
427427 && let ItemKind :: Impl ( impl_ref) =
428428 self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
429429 {
430- if self . tcx . visibility ( trait_id) . is_public ( )
431- && matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) )
430+ if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) )
432431 && !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
433432 {
434433 continue ;
@@ -487,32 +486,47 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
487486
488487 fn solve_rest_impl_items ( & mut self , mut unsolved_impl_items : Vec < ( hir:: ItemId , LocalDefId ) > ) {
489488 let mut ready;
490- ( ready, unsolved_impl_items) = unsolved_impl_items
491- . into_iter ( )
492- . partition ( |& ( impl_id, _) | self . impl_item_with_used_self ( impl_id) ) ;
489+ ( ready, unsolved_impl_items) =
490+ unsolved_impl_items. into_iter ( ) . partition ( |& ( impl_id, impl_item_id) | {
491+ self . impl_item_with_used_self_and_trait_term ( impl_id, impl_item_id)
492+ } ) ;
493493
494494 while !ready. is_empty ( ) {
495495 self . worklist =
496496 ready. into_iter ( ) . map ( |( _, id) | ( id, ComesFromAllowExpect :: No ) ) . collect ( ) ;
497497 self . mark_live_symbols ( ) ;
498498
499- ( ready, unsolved_impl_items) = unsolved_impl_items
500- . into_iter ( )
501- . partition ( |& ( impl_id, _) | self . impl_item_with_used_self ( impl_id) ) ;
499+ ( ready, unsolved_impl_items) =
500+ unsolved_impl_items. into_iter ( ) . partition ( |& ( impl_id, impl_item_id) | {
501+ self . impl_item_with_used_self_and_trait_term ( impl_id, impl_item_id)
502+ } ) ;
502503 }
503504 }
504505
505- fn impl_item_with_used_self ( & mut self , impl_id : hir:: ItemId ) -> bool {
506+ fn impl_item_with_used_self_and_trait_term (
507+ & mut self ,
508+ impl_id : hir:: ItemId ,
509+ impl_item_id : LocalDefId ,
510+ ) -> bool {
506511 if let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
507512 self . tcx . hir ( ) . item ( impl_id) . expect_impl ( ) . self_ty . kind
508513 && let Res :: Def ( def_kind, def_id) = path. res
509514 && let Some ( local_def_id) = def_id. as_local ( )
510515 && matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
511516 {
512- self . live_symbols . contains ( & local_def_id)
513- } else {
514- false
517+ if self . tcx . visibility ( impl_item_id) . is_public ( ) {
518+ return self . live_symbols . contains ( & local_def_id) ;
519+ } else if let Some ( trait_item_id) = self
520+ . tcx
521+ . impl_item_trait_item_ids ( impl_id. owner_id . to_def_id ( ) )
522+ . get ( & impl_item_id. to_def_id ( ) )
523+ && let Some ( local_id) = trait_item_id. as_local ( )
524+ {
525+ return self . live_symbols . contains ( & local_id)
526+ && self . live_symbols . contains ( & local_def_id) ;
527+ }
515528 }
529+ false
516530 }
517531}
518532
@@ -753,8 +767,8 @@ fn check_item<'tcx>(
753767 && ( ty_is_pub || may_construct_self) )
754768 {
755769 worklist. push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
756- } else if of_trait && tcx . visibility ( local_def_id ) . is_public ( ) {
757- // pub method && private ty & methods not construct self
770+ } else if of_trait {
771+ // private ty & methods not construct self
758772 unsolved_impl_items. push ( ( id, local_def_id) ) ;
759773 } else if let Some ( comes_from_allow) =
760774 has_allow_dead_code_or_lang_attr ( tcx, local_def_id)
0 commit comments