@@ -165,13 +165,6 @@ struct EmbargoVisitor<'a, 'tcx: 'a> {
165165 // may jump across private boundaries through reexport statements or type aliases.
166166 exported_items : ExportedItems ,
167167
168- // This sets contains all the destination nodes which are publicly
169- // re-exported. This is *not* a set of all reexported nodes, only a set of
170- // all nodes which are reexported *and* reachable from external crates. This
171- // means that the destination of the reexport is exported, and hence the
172- // destination must also be exported.
173- reexports : NodeSet ,
174-
175168 // Items that are directly public without help of reexports or type aliases.
176169 // These two fields are closely related to one another in that they are only
177170 // used for generation of the `public_items` set, not for privacy checking at
@@ -185,7 +178,9 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> {
185178 fn is_public_exported_ty ( & self , ty : & hir:: Ty ) -> ( bool , bool ) {
186179 if let hir:: TyPath ( ..) = ty. node {
187180 match self . tcx . def_map . borrow ( ) . get ( & ty. id ) . unwrap ( ) . full_def ( ) {
188- def:: DefPrimTy ( ..) | def:: DefSelfTy ( ..) => ( true , true ) ,
181+ def:: DefPrimTy ( ..) | def:: DefSelfTy ( ..) | def:: DefTyParam ( ..) => {
182+ ( true , true )
183+ }
189184 def => {
190185 if let Some ( node_id) = self . tcx . map . as_local_node_id ( def. def_id ( ) ) {
191186 ( self . public_items . contains ( & node_id) ,
@@ -235,7 +230,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
235230 _ => {
236231 self . prev_public = self . prev_public && item. vis == hir:: Public ;
237232 self . prev_exported = ( self . prev_exported && item. vis == hir:: Public ) ||
238- self . reexports . contains ( & item. id ) ;
233+ self . exported_items . contains ( & item. id ) ;
239234
240235 self . maybe_insert_id ( item. id ) ;
241236 }
@@ -272,25 +267,26 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
272267 }
273268 }
274269
275- // It's not known until monomorphization if a trait impl item should be reachable
276- // from external crates or not. So, we conservatively mark all of them exported and
277- // the reachability pass (middle::reachable) marks all exported items as reachable.
278- // For example of private trait impl for private type that should be reachable see
279- // src/test/auxiliary/issue-11225-3.rs
270+ // Trait impl and its items are public/exported if both the self type and the trait
271+ // of this impl are public/exported
280272 hir:: ItemImpl ( _, _, _, Some ( ref trait_ref) , ref ty, ref impl_items) => {
281- let ( public_ty, _exported_ty ) = self . is_public_exported_ty ( & ty) ;
282- let ( public_trait, _exported_trait ) = self . is_public_exported_trait ( trait_ref) ;
273+ let ( public_ty, exported_ty ) = self . is_public_exported_ty ( & ty) ;
274+ let ( public_trait, exported_trait ) = self . is_public_exported_trait ( trait_ref) ;
283275
284276 if public_ty && public_trait {
285277 self . public_items . insert ( item. id ) ;
286278 }
287- self . exported_items . insert ( item. id ) ;
279+ if exported_ty && exported_trait {
280+ self . exported_items . insert ( item. id ) ;
281+ }
288282
289283 for impl_item in impl_items {
290284 if public_ty && public_trait {
291285 self . public_items . insert ( impl_item. id ) ;
292286 }
293- self . exported_items . insert ( impl_item. id ) ;
287+ if exported_ty && exported_trait {
288+ self . exported_items . insert ( impl_item. id ) ;
289+ }
294290 }
295291 }
296292
@@ -332,8 +328,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
332328 match self . tcx . def_map . borrow ( ) . get ( & ty. id ) . unwrap ( ) . full_def ( ) {
333329 def:: DefPrimTy ( ..) | def:: DefSelfTy ( ..) | def:: DefTyParam ( ..) => { } ,
334330 def => {
335- let did = def. def_id ( ) ;
336- if let Some ( node_id) = self . tcx . map . as_local_node_id ( did) {
331+ if let Some ( node_id) = self . tcx . map . as_local_node_id ( def. def_id ( ) ) {
337332 self . exported_items . insert ( node_id) ;
338333 }
339334 }
@@ -345,7 +340,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
345340 for foreign_item in & foreign_mod. items {
346341 let public = self . prev_public && foreign_item. vis == hir:: Public ;
347342 let exported = ( self . prev_exported && foreign_item. vis == hir:: Public ) ||
348- self . reexports . contains ( & foreign_item. id ) ;
343+ self . exported_items . contains ( & foreign_item. id ) ;
349344
350345 if public {
351346 self . public_items . insert ( foreign_item. id ) ;
@@ -385,7 +380,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
385380 assert ! ( self . export_map. contains_key( & id) , "wut {}" , id) ;
386381 for export in self . export_map . get ( & id) . unwrap ( ) {
387382 if let Some ( node_id) = self . tcx . map . as_local_node_id ( export. def_id ) {
388- self . reexports . insert ( node_id) ;
383+ self . exported_items . insert ( node_id) ;
389384 }
390385 }
391386 }
@@ -1530,17 +1525,14 @@ pub fn check_crate(tcx: &ty::ctxt,
15301525 tcx : tcx,
15311526 exported_items : NodeSet ( ) ,
15321527 public_items : NodeSet ( ) ,
1533- reexports : NodeSet ( ) ,
15341528 export_map : export_map,
15351529 prev_exported : true ,
15361530 prev_public : true ,
15371531 } ;
15381532 loop {
1539- let before = ( visitor. exported_items . len ( ) , visitor. public_items . len ( ) ,
1540- visitor. reexports . len ( ) ) ;
1533+ let before = ( visitor. exported_items . len ( ) , visitor. public_items . len ( ) ) ;
15411534 visit:: walk_crate ( & mut visitor, krate) ;
1542- let after = ( visitor. exported_items . len ( ) , visitor. public_items . len ( ) ,
1543- visitor. reexports . len ( ) ) ;
1535+ let after = ( visitor. exported_items . len ( ) , visitor. public_items . len ( ) ) ;
15441536 if after == before {
15451537 break
15461538 }
0 commit comments