@@ -344,13 +344,14 @@ trait VisibilityLike: Sized {
344344 // associated types for which we can't determine visibility precisely.
345345 fn of_impl < const SHALLOW : bool > (
346346 def_id : LocalDefId ,
347+ of_trait : bool ,
347348 tcx : TyCtxt < ' _ > ,
348349 effective_visibilities : & EffectiveVisibilities ,
349350 ) -> Self {
350351 let mut find = FindMin :: < _ , SHALLOW > { tcx, effective_visibilities, min : Self :: MAX } ;
351352 find. visit ( tcx. type_of ( def_id) . instantiate_identity ( ) ) ;
352- if let Some ( trait_ref ) = tcx . impl_trait_ref ( def_id ) {
353- find. visit_trait ( trait_ref . instantiate_identity ( ) ) ;
353+ if of_trait {
354+ find. visit_trait ( tcx . impl_trait_ref ( def_id ) . unwrap ( ) . instantiate_identity ( ) ) ;
354355 }
355356 find. min
356357 }
@@ -699,13 +700,20 @@ impl<'tcx> EmbargoVisitor<'tcx> {
699700 // its trait if it exists (which require reaching the `DefId`s in them).
700701 let item_ev = EffectiveVisibility :: of_impl :: < true > (
701702 owner_id. def_id ,
703+ of_trait,
702704 self . tcx ,
703705 & self . effective_visibilities ,
704706 ) ;
705707
706708 self . update_eff_vis ( owner_id. def_id , item_ev, None , Level :: Direct ) ;
707709
708- self . reach ( owner_id. def_id , item_ev) . generics ( ) . predicates ( ) . ty ( ) . trait_ref ( ) ;
710+ {
711+ let mut reach = self . reach ( owner_id. def_id , item_ev) ;
712+ reach. generics ( ) . predicates ( ) . ty ( ) ;
713+ if of_trait {
714+ reach. trait_ref ( ) ;
715+ }
716+ }
709717
710718 for assoc_item in self . tcx . associated_items ( owner_id) . in_definition_order ( ) {
711719 if assoc_item. is_impl_trait_in_trait ( ) {
@@ -820,9 +828,9 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
820828 }
821829
822830 fn trait_ref ( & mut self ) -> & mut Self {
823- if let Some ( trait_ref ) = self . ev . tcx . impl_trait_ref ( self . item_def_id ) {
824- self . visit_trait ( trait_ref . instantiate_identity ( ) ) ;
825- }
831+ self . visit_trait (
832+ self . ev . tcx . impl_trait_ref ( self . item_def_id ) . unwrap ( ) . instantiate_identity ( ) ,
833+ ) ;
826834 self
827835 }
828836}
@@ -1395,9 +1403,8 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13951403
13961404 fn trait_ref ( & mut self ) -> & mut Self {
13971405 self . in_primary_interface = true ;
1398- if let Some ( trait_ref) = self . tcx . impl_trait_ref ( self . item_def_id ) {
1399- let _ = self . visit_trait ( trait_ref. instantiate_identity ( ) ) ;
1400- }
1406+ let _ = self
1407+ . visit_trait ( self . tcx . impl_trait_ref ( self . item_def_id ) . unwrap ( ) . instantiate_identity ( ) ) ;
14011408 self
14021409 }
14031410
@@ -1666,7 +1673,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16661673 // A trait impl is public when both its type and its trait are public
16671674 // Subitems of trait impls have inherited publicity.
16681675 DefKind :: Impl { of_trait } => {
1669- let impl_vis = ty:: Visibility :: of_impl :: < false > ( def_id, tcx, & Default :: default ( ) ) ;
1676+ let impl_vis =
1677+ ty:: Visibility :: of_impl :: < false > ( def_id, of_trait, tcx, & Default :: default ( ) ) ;
16701678
16711679 // We are using the non-shallow version here, unlike when building the
16721680 // effective visisibilities table to avoid large number of false positives.
@@ -1679,8 +1687,12 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16791687 // lints shouldn't be emitted even if `from` effective visibility
16801688 // is larger than `Priv` nominal visibility and if `Priv` can leak
16811689 // in some scenarios due to type inference.
1682- let impl_ev =
1683- EffectiveVisibility :: of_impl :: < false > ( def_id, tcx, self . effective_visibilities ) ;
1690+ let impl_ev = EffectiveVisibility :: of_impl :: < false > (
1691+ def_id,
1692+ of_trait,
1693+ tcx,
1694+ self . effective_visibilities ,
1695+ ) ;
16841696
16851697 let mut check = self . check ( def_id, impl_vis, Some ( impl_ev) ) ;
16861698
@@ -1694,7 +1706,10 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16941706 // normalization they produce very ridiculous false positives.
16951707 // FIXME: Remove this when full normalization is implemented.
16961708 check. skip_assoc_tys = true ;
1697- check. ty ( ) . trait_ref ( ) ;
1709+ check. ty ( ) ;
1710+ if of_trait {
1711+ check. trait_ref ( ) ;
1712+ }
16981713
16991714 for assoc_item in tcx. associated_items ( id. owner_id ) . in_definition_order ( ) {
17001715 if assoc_item. is_impl_trait_in_trait ( ) {
0 commit comments