@@ -165,13 +165,6 @@ struct EmbargoVisitor<'a, 'tcx: 'a> {
165
165
// may jump across private boundaries through reexport statements or type aliases.
166
166
exported_items : ExportedItems ,
167
167
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
-
175
168
// Items that are directly public without help of reexports or type aliases.
176
169
// These two fields are closely related to one another in that they are only
177
170
// used for generation of the `public_items` set, not for privacy checking at
@@ -185,7 +178,9 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> {
185
178
fn is_public_exported_ty ( & self , ty : & hir:: Ty ) -> ( bool , bool ) {
186
179
if let hir:: TyPath ( ..) = ty. node {
187
180
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
+ }
189
184
def => {
190
185
if let Some ( node_id) = self . tcx . map . as_local_node_id ( def. def_id ( ) ) {
191
186
( self . public_items . contains ( & node_id) ,
@@ -235,7 +230,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
235
230
_ => {
236
231
self . prev_public = self . prev_public && item. vis == hir:: Public ;
237
232
self . prev_exported = ( self . prev_exported && item. vis == hir:: Public ) ||
238
- self . reexports . contains ( & item. id ) ;
233
+ self . exported_items . contains ( & item. id ) ;
239
234
240
235
self . maybe_insert_id ( item. id ) ;
241
236
}
@@ -272,25 +267,26 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
272
267
}
273
268
}
274
269
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
280
272
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) ;
283
275
284
276
if public_ty && public_trait {
285
277
self . public_items . insert ( item. id ) ;
286
278
}
287
- self . exported_items . insert ( item. id ) ;
279
+ if exported_ty && exported_trait {
280
+ self . exported_items . insert ( item. id ) ;
281
+ }
288
282
289
283
for impl_item in impl_items {
290
284
if public_ty && public_trait {
291
285
self . public_items . insert ( impl_item. id ) ;
292
286
}
293
- self . exported_items . insert ( impl_item. id ) ;
287
+ if exported_ty && exported_trait {
288
+ self . exported_items . insert ( impl_item. id ) ;
289
+ }
294
290
}
295
291
}
296
292
@@ -332,8 +328,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
332
328
match self . tcx . def_map . borrow ( ) . get ( & ty. id ) . unwrap ( ) . full_def ( ) {
333
329
def:: DefPrimTy ( ..) | def:: DefSelfTy ( ..) | def:: DefTyParam ( ..) => { } ,
334
330
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 ( ) ) {
337
332
self . exported_items . insert ( node_id) ;
338
333
}
339
334
}
@@ -345,7 +340,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
345
340
for foreign_item in & foreign_mod. items {
346
341
let public = self . prev_public && foreign_item. vis == hir:: Public ;
347
342
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 ) ;
349
344
350
345
if public {
351
346
self . public_items . insert ( foreign_item. id ) ;
@@ -385,7 +380,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
385
380
assert ! ( self . export_map. contains_key( & id) , "wut {}" , id) ;
386
381
for export in self . export_map . get ( & id) . unwrap ( ) {
387
382
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) ;
389
384
}
390
385
}
391
386
}
@@ -1530,17 +1525,14 @@ pub fn check_crate(tcx: &ty::ctxt,
1530
1525
tcx : tcx,
1531
1526
exported_items : NodeSet ( ) ,
1532
1527
public_items : NodeSet ( ) ,
1533
- reexports : NodeSet ( ) ,
1534
1528
export_map : export_map,
1535
1529
prev_exported : true ,
1536
1530
prev_public : true ,
1537
1531
} ;
1538
1532
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 ( ) ) ;
1541
1534
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 ( ) ) ;
1544
1536
if after == before {
1545
1537
break
1546
1538
}
0 commit comments