@@ -35,6 +35,11 @@ type Context<'a> = (&'a method_map, &'a resolve::ExportMap2);
35
35
/// A set of AST nodes exported by the crate.
36
36
pub type ExportedItems = HashSet < ast:: NodeId > ;
37
37
38
+ /// A set of AST nodes that are fully public in the crate. This map is used for
39
+ /// documentation purposes (reexporting a private struct inlines the doc,
40
+ /// reexporting a public struct doesn't inline the doc).
41
+ pub type PublicItems = HashSet < ast:: NodeId > ;
42
+
38
43
////////////////////////////////////////////////////////////////////////////////
39
44
/// The parent visitor, used to determine what's the parent of what (node-wise)
40
45
////////////////////////////////////////////////////////////////////////////////
@@ -165,6 +170,12 @@ struct EmbargoVisitor<'a> {
165
170
// means that the destination of the reexport is exported, and hence the
166
171
// destination must also be exported.
167
172
reexports : HashSet < ast:: NodeId > ,
173
+
174
+ // These two fields are closely related to one another in that they are only
175
+ // used for generation of the 'PublicItems' set, not for privacy checking at
176
+ // all
177
+ public_items : PublicItems ,
178
+ prev_public : bool ,
168
179
}
169
180
170
181
impl < ' a > EmbargoVisitor < ' a > {
@@ -186,7 +197,13 @@ impl<'a> EmbargoVisitor<'a> {
186
197
187
198
impl < ' a > Visitor < ( ) > for EmbargoVisitor < ' a > {
188
199
fn visit_item ( & mut self , item : & ast:: item , _: ( ) ) {
189
- let orig_all_pub = self . prev_exported ;
200
+ let orig_all_pub = self . prev_public ;
201
+ self . prev_public = orig_all_pub && item. vis == ast:: public;
202
+ if self . prev_public {
203
+ self . public_items . insert ( item. id ) ;
204
+ }
205
+
206
+ let orig_all_exported = self . prev_exported ;
190
207
match item. node {
191
208
// impls/extern blocks do not break the "public chain" because they
192
209
// cannot have visibility qualifiers on them anyway
@@ -202,7 +219,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
202
219
// `pub` is explicitly listed.
203
220
_ => {
204
221
self . prev_exported =
205
- ( orig_all_pub && item. vis == ast:: public) ||
222
+ ( orig_all_exported && item. vis == ast:: public) ||
206
223
self . reexports . contains ( & item. id ) ;
207
224
}
208
225
}
@@ -304,7 +321,8 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
304
321
305
322
visit:: walk_item ( self , item, ( ) ) ;
306
323
307
- self . prev_exported = orig_all_pub;
324
+ self . prev_exported = orig_all_exported;
325
+ self . prev_public = orig_all_pub;
308
326
}
309
327
310
328
fn visit_foreign_item ( & mut self , a : & ast:: foreign_item , _: ( ) ) {
@@ -1002,7 +1020,7 @@ pub fn check_crate(tcx: ty::ctxt,
1002
1020
exp_map2 : & resolve:: ExportMap2 ,
1003
1021
external_exports : resolve:: ExternalExports ,
1004
1022
last_private_map : resolve:: LastPrivateMap ,
1005
- crate : & ast:: Crate ) -> ExportedItems {
1023
+ crate : & ast:: Crate ) -> ( ExportedItems , PublicItems ) {
1006
1024
// Figure out who everyone's parent is
1007
1025
let mut visitor = ParentVisitor {
1008
1026
parents : HashMap :: new ( ) ,
@@ -1038,9 +1056,11 @@ pub fn check_crate(tcx: ty::ctxt,
1038
1056
let mut visitor = EmbargoVisitor {
1039
1057
tcx : tcx,
1040
1058
exported_items : HashSet :: new ( ) ,
1059
+ public_items : HashSet :: new ( ) ,
1041
1060
reexports : HashSet :: new ( ) ,
1042
1061
exp_map2 : exp_map2,
1043
1062
prev_exported : true ,
1063
+ prev_public : true ,
1044
1064
} ;
1045
1065
loop {
1046
1066
let before = visitor. exported_items . len ( ) ;
@@ -1050,5 +1070,6 @@ pub fn check_crate(tcx: ty::ctxt,
1050
1070
}
1051
1071
}
1052
1072
1053
- return visitor. exported_items ;
1073
+ let EmbargoVisitor { exported_items, public_items, .. } = visitor;
1074
+ return ( exported_items, public_items) ;
1054
1075
}
0 commit comments