@@ -1495,6 +1495,16 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
1495
1495
}
1496
1496
1497
1497
fn check_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
1498
+ if self . leaks_private_dep ( def_id) {
1499
+ self . tcx . lint_node ( lint:: builtin:: LEAKED_PRIVATE_DEPENDENCY ,
1500
+ self . item_id ,
1501
+ self . span ,
1502
+ & format ! ( "{} `{}` from private dependency '{}' in public \
1503
+ interface", kind, descr,
1504
+ self . tcx. crate_name( def_id. krate) ) ) ;
1505
+
1506
+ }
1507
+
1498
1508
let node_id = match self . tcx . hir ( ) . as_local_node_id ( def_id) {
1499
1509
Some ( node_id) => node_id,
1500
1510
None => return false ,
@@ -1520,16 +1530,7 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
1520
1530
1521
1531
}
1522
1532
1523
- if self . leaks_private_dep ( trait_ref. def_id ) {
1524
- self . tcx . lint_node ( lint:: builtin:: LEAKED_PRIVATE_DEPENDENCY ,
1525
- self . item_id ,
1526
- self . span ,
1527
- & format ! ( "trait `{}` from private dependency '{}' in public \
1528
- interface", trait_ref,
1529
- self . tcx. crate_name( trait_ref. def_id. krate) ) ) ;
1530
-
1531
- }
1532
-
1533
+ false
1533
1534
}
1534
1535
1535
1536
/// An item is 'leaked' from a private dependency if all
@@ -1551,80 +1552,6 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
1551
1552
}
1552
1553
}
1553
1554
1554
- impl < ' a , ' tcx : ' a > TypeVisitor < ' tcx > for SearchInterfaceForPrivateItemsVisitor < ' a , ' tcx > {
1555
- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
1556
- let ty_def_id = match ty. sty {
1557
- ty:: Adt ( adt, _) => Some ( adt. did ) ,
1558
- ty:: Foreign ( did) => Some ( did) ,
1559
- ty:: Dynamic ( ref obj, ..) => Some ( obj. principal ( ) . def_id ( ) ) ,
1560
- ty:: Projection ( ref proj) => {
1561
- if self . required_visibility == ty:: Visibility :: Invisible {
1562
- // Conservatively approximate the whole type alias as public without
1563
- // recursing into its components when determining impl publicity.
1564
- // For example, `impl <Type as Trait>::Alias {...}` may be a public impl
1565
- // even if both `Type` and `Trait` are private.
1566
- // Ideally, associated types should be substituted in the same way as
1567
- // free type aliases, but this isn't done yet.
1568
- return false ;
1569
- }
1570
- let trait_ref = proj. trait_ref ( self . tcx ) ;
1571
- Some ( trait_ref. def_id )
1572
- }
1573
- _ => None
1574
- } ;
1575
-
1576
- if let Some ( def_id) = ty_def_id {
1577
- // Non-local means public (private items can't leave their crate, modulo bugs).
1578
- if let Some ( node_id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
1579
- let hir_vis = match self . tcx . hir ( ) . find ( node_id) {
1580
- Some ( Node :: Item ( item) ) => & item. vis ,
1581
- Some ( Node :: ForeignItem ( item) ) => & item. vis ,
1582
- _ => bug ! ( "expected item of foreign item" ) ,
1583
- } ;
1584
-
1585
- let vis = ty:: Visibility :: from_hir ( hir_vis, node_id, self . tcx ) ;
1586
-
1587
- if !vis. is_at_least ( self . min_visibility , self . tcx ) {
1588
- self . min_visibility = vis;
1589
- }
1590
- if !vis. is_at_least ( self . required_visibility , self . tcx ) {
1591
- let vis_adj = match hir_vis. node {
1592
- hir:: VisibilityKind :: Crate ( _) => "crate-visible" ,
1593
- hir:: VisibilityKind :: Restricted { .. } => "restricted" ,
1594
- _ => "private"
1595
- } ;
1596
-
1597
- if self . has_pub_restricted || self . has_old_errors || self . in_assoc_ty {
1598
- let mut err = struct_span_err ! ( self . tcx. sess, self . span, E0446 ,
1599
- "{} type `{}` in public interface" , vis_adj, ty) ;
1600
- err. span_label ( self . span , format ! ( "can't leak {} type" , vis_adj) ) ;
1601
- err. span_label ( hir_vis. span , format ! ( "`{}` declared as {}" , ty, vis_adj) ) ;
1602
- err. emit ( ) ;
1603
- } else {
1604
- self . tcx . lint_node ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
1605
- node_id,
1606
- self . span ,
1607
- & format ! ( "{} type `{}` in public \
1608
- interface (error E0446)", vis_adj, ty) ) ;
1609
- }
1610
- }
1611
-
1612
- }
1613
-
1614
- if self . leaks_private_dep ( def_id) {
1615
- self . tcx . lint_node ( lint:: builtin:: LEAKED_PRIVATE_DEPENDENCY ,
1616
- self . item_id ,
1617
- self . span ,
1618
- & format ! ( "type '{}' from private dependency '{}' in \
1619
- public interface", ty,
1620
- self . tcx. crate_name( def_id. krate) ) ) ;
1621
- }
1622
-
1623
- }
1624
-
1625
- ty. super_visit_with ( self )
1626
- }
1627
- }
1628
1555
1629
1556
/*struct LeakedPrivateDependenciesVisitor<'a, 'tcx: 'a> {
1630
1557
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -1649,6 +1576,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LeakedPrivateDependenciesVisitor<'a, 'tcx> {
1649
1576
1650
1577
}*/
1651
1578
1579
+
1580
+
1581
+ impl < ' a , ' tcx > DefIdVisitor < ' a , ' tcx > for SearchInterfaceForPrivateItemsVisitor < ' a , ' tcx > {
1582
+ fn tcx ( & self ) -> TyCtxt < ' a , ' tcx , ' tcx > { self . tcx }
1583
+ fn visit_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
1584
+ self . check_def_id ( def_id, kind, descr)
1585
+ }
1586
+ }
1587
+
1652
1588
struct PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx : ' a > {
1653
1589
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1654
1590
has_pub_restricted : bool ,
0 commit comments