@@ -427,8 +427,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
427
427
&& let ItemKind :: Impl ( impl_ref) =
428
428
self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
429
429
{
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 ( ..) )
432
431
&& !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
433
432
{
434
433
continue ;
@@ -487,32 +486,47 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
487
486
488
487
fn solve_rest_impl_items ( & mut self , mut unsolved_impl_items : Vec < ( hir:: ItemId , LocalDefId ) > ) {
489
488
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
+ } ) ;
493
493
494
494
while !ready. is_empty ( ) {
495
495
self . worklist =
496
496
ready. into_iter ( ) . map ( |( _, id) | ( id, ComesFromAllowExpect :: No ) ) . collect ( ) ;
497
497
self . mark_live_symbols ( ) ;
498
498
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
+ } ) ;
502
503
}
503
504
}
504
505
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 {
506
511
if let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
507
512
self . tcx . hir ( ) . item ( impl_id) . expect_impl ( ) . self_ty . kind
508
513
&& let Res :: Def ( def_kind, def_id) = path. res
509
514
&& let Some ( local_def_id) = def_id. as_local ( )
510
515
&& matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
511
516
{
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
+ }
515
528
}
529
+ false
516
530
}
517
531
}
518
532
@@ -753,8 +767,8 @@ fn check_item<'tcx>(
753
767
&& ( ty_is_pub || may_construct_self) )
754
768
{
755
769
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
758
772
unsolved_impl_items. push ( ( id, local_def_id) ) ;
759
773
} else if let Some ( comes_from_allow) =
760
774
has_allow_dead_code_or_lang_attr ( tcx, local_def_id)
0 commit comments