@@ -35,6 +35,11 @@ type Context<'a> = (&'a method_map, &'a resolve::ExportMap2);
3535/// A set of AST nodes exported by the crate.
3636pub type ExportedItems = HashSet < ast:: NodeId > ;
3737
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+
3843////////////////////////////////////////////////////////////////////////////////
3944/// The parent visitor, used to determine what's the parent of what (node-wise)
4045////////////////////////////////////////////////////////////////////////////////
@@ -165,6 +170,12 @@ struct EmbargoVisitor<'a> {
165170 // means that the destination of the reexport is exported, and hence the
166171 // destination must also be exported.
167172 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 ,
168179}
169180
170181impl < ' a > EmbargoVisitor < ' a > {
@@ -186,7 +197,13 @@ impl<'a> EmbargoVisitor<'a> {
186197
187198impl < ' a > Visitor < ( ) > for EmbargoVisitor < ' a > {
188199 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 ;
190207 match item. node {
191208 // impls/extern blocks do not break the "public chain" because they
192209 // cannot have visibility qualifiers on them anyway
@@ -202,7 +219,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
202219 // `pub` is explicitly listed.
203220 _ => {
204221 self . prev_exported =
205- ( orig_all_pub && item. vis == ast:: public) ||
222+ ( orig_all_exported && item. vis == ast:: public) ||
206223 self . reexports . contains ( & item. id ) ;
207224 }
208225 }
@@ -304,7 +321,8 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
304321
305322 visit:: walk_item ( self , item, ( ) ) ;
306323
307- self . prev_exported = orig_all_pub;
324+ self . prev_exported = orig_all_exported;
325+ self . prev_public = orig_all_pub;
308326 }
309327
310328 fn visit_foreign_item ( & mut self , a : & ast:: foreign_item , _: ( ) ) {
@@ -1002,7 +1020,7 @@ pub fn check_crate(tcx: ty::ctxt,
10021020 exp_map2 : & resolve:: ExportMap2 ,
10031021 external_exports : resolve:: ExternalExports ,
10041022 last_private_map : resolve:: LastPrivateMap ,
1005- crate : & ast:: Crate ) -> ExportedItems {
1023+ crate : & ast:: Crate ) -> ( ExportedItems , PublicItems ) {
10061024 // Figure out who everyone's parent is
10071025 let mut visitor = ParentVisitor {
10081026 parents : HashMap :: new ( ) ,
@@ -1038,9 +1056,11 @@ pub fn check_crate(tcx: ty::ctxt,
10381056 let mut visitor = EmbargoVisitor {
10391057 tcx : tcx,
10401058 exported_items : HashSet :: new ( ) ,
1059+ public_items : HashSet :: new ( ) ,
10411060 reexports : HashSet :: new ( ) ,
10421061 exp_map2 : exp_map2,
10431062 prev_exported : true ,
1063+ prev_public : true ,
10441064 } ;
10451065 loop {
10461066 let before = visitor. exported_items . len ( ) ;
@@ -1050,5 +1070,6 @@ pub fn check_crate(tcx: ty::ctxt,
10501070 }
10511071 }
10521072
1053- return visitor. exported_items ;
1073+ let EmbargoVisitor { exported_items, public_items, .. } = visitor;
1074+ return ( exported_items, public_items) ;
10541075}
0 commit comments