@@ -1849,49 +1849,26 @@ impl DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
18491849 }
18501850}
18511851
1852- struct PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1852+ struct PrivateItemsInPublicInterfacesVisitor < ' tcx > {
18531853 tcx : TyCtxt < ' tcx > ,
18541854 has_pub_restricted : bool ,
1855- old_error_set : & ' a HirIdSet ,
1855+ old_error_set_ancestry : HirIdSet ,
18561856}
18571857
1858- impl < ' a , ' tcx > PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1858+ impl < ' tcx > PrivateItemsInPublicInterfacesVisitor < ' tcx > {
18591859 fn check (
18601860 & self ,
18611861 item_id : hir:: HirId ,
18621862 required_visibility : ty:: Visibility ,
18631863 ) -> SearchInterfaceForPrivateItemsVisitor < ' tcx > {
1864- let mut has_old_errors = false ;
1865-
1866- // Slow path taken only if there any errors in the crate.
1867- for & id in self . old_error_set {
1868- // Walk up the nodes until we find `item_id` (or we hit a root).
1869- let mut id = id;
1870- loop {
1871- if id == item_id {
1872- has_old_errors = true ;
1873- break ;
1874- }
1875- let parent = self . tcx . hir ( ) . get_parent_node ( id) ;
1876- if parent == id {
1877- break ;
1878- }
1879- id = parent;
1880- }
1881-
1882- if has_old_errors {
1883- break ;
1884- }
1885- }
1886-
18871864 SearchInterfaceForPrivateItemsVisitor {
18881865 tcx : self . tcx ,
18891866 item_id,
18901867 item_def_id : self . tcx . hir ( ) . local_def_id ( item_id) . to_def_id ( ) ,
18911868 span : self . tcx . hir ( ) . span ( item_id) ,
18921869 required_visibility,
18931870 has_pub_restricted : self . has_pub_restricted ,
1894- has_old_errors,
1871+ has_old_errors : self . old_error_set_ancestry . contains ( & item_id ) ,
18951872 in_assoc_ty : false ,
18961873 }
18971874 }
@@ -1917,7 +1894,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
19171894 }
19181895}
19191896
1920- impl < ' a , ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1897+ impl < ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' tcx > {
19211898 type Map = Map < ' tcx > ;
19221899
19231900 fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
@@ -2137,11 +2114,22 @@ fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) {
21372114 pub_restricted_visitor. has_pub_restricted
21382115 } ;
21392116
2117+ let mut old_error_set_ancestry = HirIdSet :: default ( ) ;
2118+ for mut id in visitor. old_error_set . iter ( ) . copied ( ) {
2119+ loop {
2120+ if !old_error_set_ancestry. insert ( id) {
2121+ break ;
2122+ }
2123+ let parent = tcx. hir ( ) . get_parent_node ( id) ;
2124+ if parent == id {
2125+ break ;
2126+ }
2127+ id = parent;
2128+ }
2129+ }
2130+
21402131 // Check for private types and traits in public interfaces.
2141- let mut visitor = PrivateItemsInPublicInterfacesVisitor {
2142- tcx,
2143- has_pub_restricted,
2144- old_error_set : & visitor. old_error_set ,
2145- } ;
2132+ let mut visitor =
2133+ PrivateItemsInPublicInterfacesVisitor { tcx, has_pub_restricted, old_error_set_ancestry } ;
21462134 krate. visit_all_item_likes ( & mut DeepVisitor :: new ( & mut visitor) ) ;
21472135}
0 commit comments