@@ -486,9 +486,6 @@ declare_lint! {
486
486
pub struct MissingDoc {
487
487
/// Stack of whether `#[doc(hidden)]` is set at each level which has lint attributes.
488
488
doc_hidden_stack : Vec < bool > ,
489
-
490
- /// Private traits or trait items that leaked through. Don't check their methods.
491
- private_traits : FxHashSet < hir:: HirId > ,
492
489
}
493
490
494
491
impl_lint_pass ! ( MissingDoc => [ MISSING_DOCS ] ) ;
@@ -519,7 +516,7 @@ fn has_doc(attr: &ast::Attribute) -> bool {
519
516
520
517
impl MissingDoc {
521
518
pub fn new ( ) -> MissingDoc {
522
- MissingDoc { doc_hidden_stack : vec ! [ false ] , private_traits : FxHashSet :: default ( ) }
519
+ MissingDoc { doc_hidden_stack : vec ! [ false ] }
523
520
}
524
521
525
522
fn doc_hidden ( & self ) -> bool {
@@ -597,36 +594,16 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
597
594
598
595
fn check_item ( & mut self , cx : & LateContext < ' _ > , it : & hir:: Item < ' _ > ) {
599
596
match it. kind {
600
- hir:: ItemKind :: Trait ( .., trait_item_refs ) => {
597
+ hir:: ItemKind :: Trait ( ..) => {
601
598
// Issue #11592: traits are always considered exported, even when private.
602
599
if cx. tcx . visibility ( it. def_id )
603
600
== ty:: Visibility :: Restricted (
604
601
cx. tcx . parent_module_from_def_id ( it. def_id ) . to_def_id ( ) ,
605
602
)
606
603
{
607
- self . private_traits . insert ( it. hir_id ( ) ) ;
608
- for trait_item_ref in trait_item_refs {
609
- self . private_traits . insert ( trait_item_ref. id . hir_id ( ) ) ;
610
- }
611
604
return ;
612
605
}
613
606
}
614
- hir:: ItemKind :: Impl ( hir:: Impl { of_trait : Some ( ref trait_ref) , items, .. } ) => {
615
- // If the trait is private, add the impl items to `private_traits` so they don't get
616
- // reported for missing docs.
617
- let real_trait = trait_ref. path . res . def_id ( ) ;
618
- let Some ( def_id) = real_trait. as_local ( ) else { return } ;
619
- if cx. tcx . visibility ( def_id)
620
- == ty:: Visibility :: Restricted (
621
- cx. tcx . parent_module_from_def_id ( it. def_id ) . to_def_id ( ) ,
622
- )
623
- {
624
- for impl_item_ref in items {
625
- self . private_traits . insert ( impl_item_ref. id . hir_id ( ) ) ;
626
- }
627
- }
628
- return ;
629
- }
630
607
hir:: ItemKind :: TyAlias ( ..)
631
608
| hir:: ItemKind :: Fn ( ..)
632
609
| hir:: ItemKind :: Macro ( ..)
@@ -646,10 +623,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
646
623
}
647
624
648
625
fn check_trait_item ( & mut self , cx : & LateContext < ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
649
- if self . private_traits . contains ( & trait_item. hir_id ( ) ) {
650
- return ;
651
- }
652
-
653
626
let ( article, desc) = cx. tcx . article_and_description ( trait_item. def_id . to_def_id ( ) ) ;
654
627
655
628
self . check_missing_docs_attrs ( cx, trait_item. def_id , trait_item. span , article, desc) ;
@@ -1389,15 +1362,16 @@ impl UnreachablePub {
1389
1362
cx : & LateContext < ' _ > ,
1390
1363
what : & str ,
1391
1364
def_id : LocalDefId ,
1365
+ span : Span ,
1392
1366
vis_span : Span ,
1393
1367
exportable : bool ,
1394
1368
) {
1395
1369
let mut applicability = Applicability :: MachineApplicable ;
1396
- if !cx. access_levels . is_reachable ( def_id) {
1370
+ if cx . tcx . visibility ( def_id ) . is_public ( ) && !cx. access_levels . is_reachable ( def_id) {
1397
1371
if vis_span. from_expansion ( ) {
1398
1372
applicability = Applicability :: MaybeIncorrect ;
1399
1373
}
1400
- let def_span = cx. tcx . def_span ( def_id ) ;
1374
+ let def_span = cx. tcx . sess . source_map ( ) . guess_head_span ( span ) ;
1401
1375
cx. struct_span_lint ( UNREACHABLE_PUB , def_span, |lint| {
1402
1376
let mut err = lint. build ( & format ! ( "unreachable `pub` {}" , what) ) ;
1403
1377
let replacement = if cx. tcx . features ( ) . crate_visibility_modifier {
@@ -1424,27 +1398,40 @@ impl UnreachablePub {
1424
1398
1425
1399
impl < ' tcx > LateLintPass < ' tcx > for UnreachablePub {
1426
1400
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
1427
- if cx. tcx . visibility ( item. def_id ) . is_public ( ) {
1428
- self . perform_lint ( cx, "item" , item. def_id , item. vis_span , true ) ;
1401
+ // Do not warn for fake `use` statements.
1402
+ if let hir:: ItemKind :: Use ( _, hir:: UseKind :: ListStem ) = & item. kind {
1403
+ return ;
1429
1404
}
1405
+ self . perform_lint ( cx, "item" , item. def_id , item. span , item. vis_span , true ) ;
1430
1406
}
1431
1407
1432
1408
fn check_foreign_item ( & mut self , cx : & LateContext < ' _ > , foreign_item : & hir:: ForeignItem < ' tcx > ) {
1433
- if cx. tcx . visibility ( foreign_item. def_id ) . is_public ( ) {
1434
- self . perform_lint ( cx, "item" , foreign_item. def_id , foreign_item. vis_span , true ) ;
1435
- }
1409
+ self . perform_lint (
1410
+ cx,
1411
+ "item" ,
1412
+ foreign_item. def_id ,
1413
+ foreign_item. span ,
1414
+ foreign_item. vis_span ,
1415
+ true ,
1416
+ ) ;
1436
1417
}
1437
1418
1438
1419
fn check_field_def ( & mut self , cx : & LateContext < ' _ > , field : & hir:: FieldDef < ' _ > ) {
1439
1420
let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) ;
1440
- if cx. tcx . visibility ( def_id) . is_public ( ) {
1441
- self . perform_lint ( cx, "field" , def_id, field. vis_span , false ) ;
1442
- }
1421
+ self . perform_lint ( cx, "field" , def_id, field. span , field. vis_span , false ) ;
1443
1422
}
1444
1423
1445
1424
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
1446
- if cx. tcx . visibility ( impl_item. def_id ) . is_public ( ) {
1447
- self . perform_lint ( cx, "item" , impl_item. def_id , impl_item. vis_span , false ) ;
1425
+ // Only lint inherent impl items.
1426
+ if cx. tcx . associated_item ( impl_item. def_id ) . trait_item_def_id . is_none ( ) {
1427
+ self . perform_lint (
1428
+ cx,
1429
+ "item" ,
1430
+ impl_item. def_id ,
1431
+ impl_item. span ,
1432
+ impl_item. vis_span ,
1433
+ false ,
1434
+ ) ;
1448
1435
}
1449
1436
}
1450
1437
}
0 commit comments