@@ -486,9 +486,6 @@ declare_lint! {
486486pub struct MissingDoc {
487487 /// Stack of whether `#[doc(hidden)]` is set at each level which has lint attributes.
488488 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 > ,
492489}
493490
494491impl_lint_pass ! ( MissingDoc => [ MISSING_DOCS ] ) ;
@@ -519,7 +516,7 @@ fn has_doc(attr: &ast::Attribute) -> bool {
519516
520517impl MissingDoc {
521518 pub fn new ( ) -> MissingDoc {
522- MissingDoc { doc_hidden_stack : vec ! [ false ] , private_traits : FxHashSet :: default ( ) }
519+ MissingDoc { doc_hidden_stack : vec ! [ false ] }
523520 }
524521
525522 fn doc_hidden ( & self ) -> bool {
@@ -597,36 +594,16 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
597594
598595 fn check_item ( & mut self , cx : & LateContext < ' _ > , it : & hir:: Item < ' _ > ) {
599596 match it. kind {
600- hir:: ItemKind :: Trait ( .., trait_item_refs ) => {
597+ hir:: ItemKind :: Trait ( ..) => {
601598 // Issue #11592: traits are always considered exported, even when private.
602599 if cx. tcx . visibility ( it. def_id )
603600 == ty:: Visibility :: Restricted (
604601 cx. tcx . parent_module_from_def_id ( it. def_id ) . to_def_id ( ) ,
605602 )
606603 {
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- }
611604 return ;
612605 }
613606 }
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- }
630607 hir:: ItemKind :: TyAlias ( ..)
631608 | hir:: ItemKind :: Fn ( ..)
632609 | hir:: ItemKind :: Macro ( ..)
@@ -646,10 +623,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
646623 }
647624
648625 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-
653626 let ( article, desc) = cx. tcx . article_and_description ( trait_item. def_id . to_def_id ( ) ) ;
654627
655628 self . check_missing_docs_attrs ( cx, trait_item. def_id , trait_item. span , article, desc) ;
@@ -1389,15 +1362,16 @@ impl UnreachablePub {
13891362 cx : & LateContext < ' _ > ,
13901363 what : & str ,
13911364 def_id : LocalDefId ,
1365+ span : Span ,
13921366 vis_span : Span ,
13931367 exportable : bool ,
13941368 ) {
13951369 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) {
13971371 if vis_span. from_expansion ( ) {
13981372 applicability = Applicability :: MaybeIncorrect ;
13991373 }
1400- let def_span = cx. tcx . def_span ( def_id ) ;
1374+ let def_span = cx. tcx . sess . source_map ( ) . guess_head_span ( span ) ;
14011375 cx. struct_span_lint ( UNREACHABLE_PUB , def_span, |lint| {
14021376 let mut err = lint. build ( & format ! ( "unreachable `pub` {}" , what) ) ;
14031377 let replacement = if cx. tcx . features ( ) . crate_visibility_modifier {
@@ -1424,27 +1398,40 @@ impl UnreachablePub {
14241398
14251399impl < ' tcx > LateLintPass < ' tcx > for UnreachablePub {
14261400 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 ;
14291404 }
1405+ self . perform_lint ( cx, "item" , item. def_id , item. span , item. vis_span , true ) ;
14301406 }
14311407
14321408 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+ ) ;
14361417 }
14371418
14381419 fn check_field_def ( & mut self , cx : & LateContext < ' _ > , field : & hir:: FieldDef < ' _ > ) {
14391420 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 ) ;
14431422 }
14441423
14451424 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+ ) ;
14481435 }
14491436 }
14501437}
0 commit comments