18
18
19
19
#![ recursion_limit="256" ]
20
20
21
- #[ macro_use] extern crate log;
22
21
#[ macro_use] extern crate rustc;
23
22
#[ macro_use] extern crate syntax;
24
23
extern crate rustc_typeck;
@@ -150,7 +149,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
150
149
}
151
150
152
151
fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
153
- debug ! ( "visit_item({:?})" , item) ;
154
152
let inherited_item_level = match item. node {
155
153
// Impls inherit level from their types and traits
156
154
hir:: ItemKind :: Impl ( ..) => {
@@ -161,21 +159,12 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
161
159
hir:: ItemKind :: ForeignMod ( ..) => {
162
160
self . prev_level
163
161
}
164
- // Impl trait return types mark their parent function.
165
- // It (and its children) are revisited if the change applies.
166
- hir:: ItemKind :: Existential ( ref ty_data) => {
167
- if let Some ( impl_trait_fn) = ty_data. impl_trait_fn {
168
- if let Some ( node_id) = self . tcx . hir . as_local_node_id ( impl_trait_fn) {
169
- self . update ( node_id, Some ( AccessLevel :: ReachableFromImplTrait ) ) ;
170
- }
171
- }
172
- if item. vis . node . is_pub ( ) { self . prev_level } else { None }
173
- }
174
162
// Other `pub` items inherit levels from parents
175
163
hir:: ItemKind :: Const ( ..) | hir:: ItemKind :: Enum ( ..) | hir:: ItemKind :: ExternCrate ( ..) |
176
164
hir:: ItemKind :: GlobalAsm ( ..) | hir:: ItemKind :: Fn ( ..) | hir:: ItemKind :: Mod ( ..) |
177
165
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Struct ( ..) |
178
166
hir:: ItemKind :: Trait ( ..) | hir:: ItemKind :: TraitAlias ( ..) |
167
+ hir:: ItemKind :: Existential ( ..) |
179
168
hir:: ItemKind :: Ty ( ..) | hir:: ItemKind :: Union ( ..) | hir:: ItemKind :: Use ( ..) => {
180
169
if item. vis . node . is_pub ( ) { self . prev_level } else { None }
181
170
}
@@ -184,8 +173,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
184
173
// Update level of the item itself
185
174
let item_level = self . update ( item. id , inherited_item_level) ;
186
175
187
- debug ! ( "item_level = {:?}" , item_level) ;
188
-
189
176
// Update levels of nested things
190
177
match item. node {
191
178
hir:: ItemKind :: Enum ( ref def, _) => {
@@ -230,7 +217,15 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
230
217
}
231
218
}
232
219
}
233
- hir:: ItemKind :: Existential ( ..) |
220
+ // Impl trait return types mark their parent function.
221
+ // It (and its children) are revisited if the change applies.
222
+ hir:: ItemKind :: Existential ( ref ty_data) => {
223
+ if let Some ( impl_trait_fn) = ty_data. impl_trait_fn {
224
+ if let Some ( node_id) = self . tcx . hir . as_local_node_id ( impl_trait_fn) {
225
+ self . update ( node_id, Some ( AccessLevel :: ReachableFromImplTrait ) ) ;
226
+ }
227
+ }
228
+ }
234
229
hir:: ItemKind :: Use ( ..) |
235
230
hir:: ItemKind :: Static ( ..) |
236
231
hir:: ItemKind :: Const ( ..) |
@@ -242,8 +237,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
242
237
hir:: ItemKind :: ExternCrate ( ..) => { }
243
238
}
244
239
245
- let orig_level = self . prev_level ;
246
- self . prev_level = item_level;
240
+ // Store this node's access level here to propagate the correct
241
+ // reachability level through interfaces and children.
242
+ let orig_level = replace ( & mut self . prev_level , item_level) ;
247
243
248
244
// Mark all items in interfaces of reachable items as reachable
249
245
match item. node {
@@ -1752,8 +1748,6 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1752
1748
}
1753
1749
visitor. update ( ast:: CRATE_NODE_ID , Some ( AccessLevel :: Public ) ) ;
1754
1750
1755
- debug ! ( "access levels after embargo: {:?}" , & visitor. access_levels) ;
1756
-
1757
1751
{
1758
1752
let mut visitor = ObsoleteVisiblePrivateTypesVisitor {
1759
1753
tcx,
@@ -1783,8 +1777,6 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1783
1777
krate. visit_all_item_likes ( & mut DeepVisitor :: new ( & mut visitor) ) ;
1784
1778
}
1785
1779
1786
- debug ! ( "final access levels: {:?}" , & visitor. access_levels) ;
1787
-
1788
1780
Lrc :: new ( visitor. access_levels )
1789
1781
}
1790
1782
0 commit comments