@@ -183,21 +183,6 @@ struct EmbargoVisitor<'a, 'tcx: 'a> {
183
183
}
184
184
185
185
impl < ' a , ' tcx > EmbargoVisitor < ' a , ' tcx > {
186
- // There are checks inside of privacy which depend on knowing whether a
187
- // trait should be exported or not. The two current consumers of this are:
188
- //
189
- // 1. Should default methods of a trait be exported?
190
- // 2. Should the methods of an implementation of a trait be exported?
191
- //
192
- // The answer to both of these questions partly rely on whether the trait
193
- // itself is exported or not. If the trait is somehow exported, then the
194
- // answers to both questions must be yes. Right now this question involves
195
- // more analysis than is currently done in rustc, so we conservatively
196
- // answer "yes" so that all traits need to be exported.
197
- fn exported_trait ( & self , _id : ast:: NodeId ) -> bool {
198
- true
199
- }
200
-
201
186
// Returns tuple (is_public, is_exported) for a type
202
187
fn is_public_exported_ty ( & self , ty : & hir:: Ty ) -> ( bool , bool ) {
203
188
if let hir:: TyPath ( ..) = ty. node {
@@ -247,15 +232,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
247
232
// added to public/exported sets based on inherited publicity.
248
233
hir:: ItemImpl ( ..) | hir:: ItemDefaultImpl ( ..) | hir:: ItemForeignMod ( ..) => { }
249
234
250
- // Traits are a little special in that even if they themselves are
251
- // not public they may still be exported.
252
- hir:: ItemTrait ( ..) => {
253
- self . prev_public = self . prev_public && item. vis == hir:: Public ;
254
- self . prev_exported = self . exported_trait ( item. id ) ;
255
-
256
- self . maybe_insert_id ( item. id ) ;
257
- }
258
-
259
235
// Private by default, hence we only retain the "public chain" if
260
236
// `pub` is explicitly listed.
261
237
_ => {
@@ -284,9 +260,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
284
260
}
285
261
}
286
262
287
- // * Inherent impls for public types only have public methods exported
288
- // * Inherent impls for private types do not need to export their methods
289
- // * Inherent impls themselves are not exported, they are nothing more than
263
+ // Public items in inherent impls for public/exported types are public/exported
264
+ // Inherent impls themselves are not public/exported, they are nothing more than
290
265
// containers for other items
291
266
hir:: ItemImpl ( _, _, _, None , ref ty, ref impl_items) => {
292
267
let ( public_ty, exported_ty) = self . is_public_exported_ty ( & ty) ;
@@ -303,42 +278,29 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
303
278
}
304
279
}
305
280
306
- // Implementations are a little tricky to determine what's exported
307
- // out of them. Here's a few cases which are currently defined:
308
- //
309
- // * Public trait impls for public types must have all methods
310
- // exported.
311
- //
312
- // * Private trait impls for public types can be ignored
313
- //
314
- // * Public trait impls for private types have their methods
315
- // exported. I'm not entirely certain that this is the correct
316
- // thing to do, but I have seen use cases of where this will cause
317
- // undefined symbols at linkage time if this case is not handled.
318
- //
319
- // * Private trait impls for private types can be completely ignored
281
+ // It's not known until monomorphization if a trait impl item should be reachable
282
+ // from external crates or not. So, we conservatively mark all of them exported and
283
+ // the reachability pass (middle::reachable) marks all exported items as reachable.
284
+ // For example of private trait impl for private type that shoud be reachable see
285
+ // src/test/auxiliary/issue-11225-3.rs
320
286
hir:: ItemImpl ( _, _, _, Some ( ref trait_ref) , ref ty, ref impl_items) => {
321
287
let ( public_ty, _exported_ty) = self . is_public_exported_ty ( & ty) ;
322
- let ( public_trait, exported_trait ) = self . is_public_exported_trait ( trait_ref) ;
288
+ let ( public_trait, _exported_trait ) = self . is_public_exported_trait ( trait_ref) ;
323
289
324
290
if public_ty && public_trait {
325
291
self . public_items . insert ( item. id ) ;
326
292
}
327
- if exported_trait {
328
- self . exported_items . insert ( item. id ) ;
329
- }
293
+ self . exported_items . insert ( item. id ) ;
330
294
331
295
for impl_item in impl_items {
332
296
if public_ty && public_trait {
333
297
self . public_items . insert ( impl_item. id ) ;
334
298
}
335
- if exported_trait {
336
- self . exported_items . insert ( impl_item. id ) ;
337
- }
299
+ self . exported_items . insert ( impl_item. id ) ;
338
300
}
339
301
}
340
302
341
- // Default trait impls are exported for public traits
303
+ // Default trait impls are public/ exported for public/exported traits
342
304
hir:: ItemDefaultImpl ( _, ref trait_ref) => {
343
305
let ( public_trait, exported_trait) = self . is_public_exported_trait ( trait_ref) ;
344
306
@@ -350,8 +312,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
350
312
}
351
313
}
352
314
353
- // Default methods on traits are all public so long as the trait
354
- // is public
315
+ // Default methods on traits are all public/exported so long as the trait
316
+ // is public/exported
355
317
hir:: ItemTrait ( _, _, _, ref trait_items) => {
356
318
for trait_item in trait_items {
357
319
self . maybe_insert_id ( trait_item. id ) ;
0 commit comments