@@ -9,8 +9,10 @@ use crate::clean::*;
9
9
use crate :: core:: DocContext ;
10
10
use crate :: fold:: DocFolder ;
11
11
use crate :: html:: markdown:: { find_testable_code, ErrorCodes , Ignore , LangString } ;
12
+ use crate :: visit_ast:: inherits_doc_hidden;
12
13
use rustc_middle:: lint:: LintLevelSource ;
13
14
use rustc_session:: lint;
15
+ use rustc_span:: symbol:: sym;
14
16
15
17
crate const CHECK_PRIVATE_ITEMS_DOC_TESTS : Pass = Pass {
16
18
name : "check-private-items-doc-tests" ,
@@ -68,6 +70,11 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
68
70
return false ;
69
71
}
70
72
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
+ }
71
78
let ( level, source) = cx. tcx . lint_level_at_node ( crate :: lint:: MISSING_DOC_CODE_EXAMPLES , hir_id) ;
72
79
level != lint:: Level :: Allow || matches ! ( source, LintLevelSource :: Default )
73
80
}
@@ -86,7 +93,9 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
86
93
find_testable_code ( & dox, & mut tests, ErrorCodes :: No , false , None ) ;
87
94
88
95
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
+ {
90
99
debug ! ( "reporting error for {:?} (hir_id={:?})" , item, hir_id) ;
91
100
let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
92
101
cx. tcx . struct_span_lint_hir (
0 commit comments