@@ -1822,49 +1822,26 @@ impl DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
1822
1822
}
1823
1823
}
1824
1824
1825
- struct PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1825
+ struct PrivateItemsInPublicInterfacesVisitor < ' tcx > {
1826
1826
tcx : TyCtxt < ' tcx > ,
1827
1827
has_pub_restricted : bool ,
1828
- old_error_set : & ' a HirIdSet ,
1828
+ old_error_set_ancestry : HirIdSet ,
1829
1829
}
1830
1830
1831
- impl < ' a , ' tcx > PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1831
+ impl < ' tcx > PrivateItemsInPublicInterfacesVisitor < ' tcx > {
1832
1832
fn check (
1833
1833
& self ,
1834
1834
item_id : hir:: HirId ,
1835
1835
required_visibility : ty:: Visibility ,
1836
1836
) -> SearchInterfaceForPrivateItemsVisitor < ' tcx > {
1837
- let mut has_old_errors = false ;
1838
-
1839
- // Slow path taken only if there any errors in the crate.
1840
- for & id in self . old_error_set {
1841
- // Walk up the nodes until we find `item_id` (or we hit a root).
1842
- let mut id = id;
1843
- loop {
1844
- if id == item_id {
1845
- has_old_errors = true ;
1846
- break ;
1847
- }
1848
- let parent = self . tcx . hir ( ) . get_parent_node ( id) ;
1849
- if parent == id {
1850
- break ;
1851
- }
1852
- id = parent;
1853
- }
1854
-
1855
- if has_old_errors {
1856
- break ;
1857
- }
1858
- }
1859
-
1860
1837
SearchInterfaceForPrivateItemsVisitor {
1861
1838
tcx : self . tcx ,
1862
1839
item_id,
1863
1840
item_def_id : self . tcx . hir ( ) . local_def_id ( item_id) . to_def_id ( ) ,
1864
1841
span : self . tcx . hir ( ) . span ( item_id) ,
1865
1842
required_visibility,
1866
1843
has_pub_restricted : self . has_pub_restricted ,
1867
- has_old_errors,
1844
+ has_old_errors : self . old_error_set_ancestry . contains ( & item_id ) ,
1868
1845
in_assoc_ty : false ,
1869
1846
}
1870
1847
}
@@ -1890,7 +1867,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
1890
1867
}
1891
1868
}
1892
1869
1893
- impl < ' a , ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
1870
+ impl < ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' tcx > {
1894
1871
type Map = Map < ' tcx > ;
1895
1872
1896
1873
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
@@ -2114,11 +2091,22 @@ fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) {
2114
2091
pub_restricted_visitor. has_pub_restricted
2115
2092
} ;
2116
2093
2094
+ let mut old_error_set_ancestry = HirIdSet :: default ( ) ;
2095
+ for mut id in visitor. old_error_set . iter ( ) . copied ( ) {
2096
+ loop {
2097
+ if !old_error_set_ancestry. insert ( id) {
2098
+ break ;
2099
+ }
2100
+ let parent = tcx. hir ( ) . get_parent_node ( id) ;
2101
+ if parent == id {
2102
+ break ;
2103
+ }
2104
+ id = parent;
2105
+ }
2106
+ }
2107
+
2117
2108
// Check for private types and traits in public interfaces.
2118
- let mut visitor = PrivateItemsInPublicInterfacesVisitor {
2119
- tcx,
2120
- has_pub_restricted,
2121
- old_error_set : & visitor. old_error_set ,
2122
- } ;
2109
+ let mut visitor =
2110
+ PrivateItemsInPublicInterfacesVisitor { tcx, has_pub_restricted, old_error_set_ancestry } ;
2123
2111
krate. visit_all_item_likes ( & mut DeepVisitor :: new ( & mut visitor) ) ;
2124
2112
}
0 commit comments