@@ -9,8 +9,10 @@ use crate::clean::*;
99use crate :: core:: DocContext ;
1010use crate :: fold:: DocFolder ;
1111use crate :: html:: markdown:: { find_testable_code, ErrorCodes , Ignore , LangString } ;
12+ use crate :: visit_ast:: inherits_doc_hidden;
1213use rustc_middle:: lint:: LintLevelSource ;
1314use rustc_session:: lint;
15+ use rustc_span:: symbol:: sym;
1416
1517crate const CHECK_PRIVATE_ITEMS_DOC_TESTS : Pass = Pass {
1618 name : "check-private-items-doc-tests" ,
@@ -68,6 +70,11 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
6870 return false ;
6971 }
7072 let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( item. def_id . expect_local ( ) ) ;
73+ if cx. tcx . hir ( ) . attrs ( hir_id) . lists ( sym:: doc) . has_word ( sym:: hidden)
74+ || inherits_doc_hidden ( cx, hir_id)
75+ {
76+ return false ;
77+ }
7178 let ( level, source) = cx. tcx . lint_level_at_node ( crate :: lint:: MISSING_DOC_CODE_EXAMPLES , hir_id) ;
7279 level != lint:: Level :: Allow || matches ! ( source, LintLevelSource :: Default )
7380}
@@ -86,7 +93,9 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
8693 find_testable_code ( & dox, & mut tests, ErrorCodes :: No , false , None ) ;
8794
8895 if tests. found_tests == 0 && cx. tcx . sess . is_nightly_build ( ) {
89- if should_have_doc_example ( cx, & item) {
96+ if cx. renderinfo . borrow ( ) . access_levels . is_public ( item. def_id )
97+ && should_have_doc_example ( cx, & item)
98+ {
9099 debug ! ( "reporting error for {:?} (hir_id={:?})" , item, hir_id) ;
91100 let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
92101 cx. tcx . struct_span_lint_hir (
0 commit comments