@@ -9,6 +9,7 @@ use crate::clean::*;
99use crate :: core:: DocContext ;
1010use crate :: fold:: DocFolder ;
1111use crate :: html:: markdown:: { find_testable_code, ErrorCodes , Ignore , LangString } ;
12+ use rustc_middle:: lint:: LintSource ;
1213use rustc_session:: lint;
1314
1415pub const CHECK_PRIVATE_ITEMS_DOC_TESTS : Pass = Pass {
@@ -56,8 +57,8 @@ impl crate::doctest::Tester for Tests {
5657 }
5758}
5859
59- pub fn should_have_doc_example ( item_kind : & clean:: ItemEnum ) -> bool {
60- ! matches ! ( item_kind ,
60+ pub fn should_have_doc_example ( cx : & DocContext < ' _ > , item : & clean:: Item ) -> bool {
61+ if matches ! ( item . inner ,
6162 clean:: StructFieldItem ( _)
6263 | clean:: VariantItem ( _)
6364 | clean:: AssocConstItem ( _, _)
@@ -69,7 +70,13 @@ pub fn should_have_doc_example(item_kind: &clean::ItemEnum) -> bool {
6970 | clean:: ImportItem ( _)
7071 | clean:: PrimitiveItem ( _)
7172 | clean:: KeywordItem ( _)
72- )
73+ ) {
74+ return false ;
75+ }
76+ let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( item. def_id . expect_local ( ) ) ;
77+ let ( level, source) =
78+ cx. tcx . lint_level_at_node ( lint:: builtin:: MISSING_DOC_CODE_EXAMPLES , hir_id) ;
79+ level != lint:: Level :: Allow || !matches ! ( source, LintSource :: Node ( ..) )
7380}
7481
7582pub fn look_for_tests < ' tcx > ( cx : & DocContext < ' tcx > , dox : & str , item : & Item ) {
@@ -88,7 +95,7 @@ pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
8895 if tests. found_tests == 0
8996 && rustc_feature:: UnstableFeatures :: from_environment ( ) . is_nightly_build ( )
9097 {
91- if should_have_doc_example ( & item. inner ) {
98+ if should_have_doc_example ( cx , & item) {
9299 debug ! ( "reporting error for {:?} (hir_id={:?})" , item, hir_id) ;
93100 let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
94101 cx. tcx . struct_span_lint_hir (
0 commit comments