44//! - PRIVATE_DOC_TESTS: this looks for private items with doc-tests.
55
66use super :: { span_of_attrs, Pass } ;
7+ use crate :: clean;
78use crate :: clean:: * ;
89use crate :: core:: DocContext ;
910use crate :: fold:: DocFolder ;
@@ -59,6 +60,22 @@ impl crate::test::Tester for Tests {
5960 }
6061}
6162
63+ pub fn should_have_doc_example ( item_kind : & clean:: ItemEnum ) -> bool {
64+ !matches ! ( item_kind,
65+ clean:: StructFieldItem ( _)
66+ | clean:: VariantItem ( _)
67+ | clean:: AssocConstItem ( _, _)
68+ | clean:: AssocTypeItem ( _, _)
69+ | clean:: TypedefItem ( _, _)
70+ | clean:: StaticItem ( _)
71+ | clean:: ConstantItem ( _)
72+ | clean:: ExternCrateItem ( _, _)
73+ | clean:: ImportItem ( _)
74+ | clean:: PrimitiveItem ( _)
75+ | clean:: KeywordItem ( _)
76+ )
77+ }
78+
6279pub fn look_for_tests < ' tcx > ( cx : & DocContext < ' tcx > , dox : & str , item : & Item ) {
6380 let hir_id = match cx. as_local_hir_id ( item. def_id ) {
6481 Some ( hir_id) => hir_id,
@@ -73,13 +90,7 @@ pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
7390 find_testable_code ( & dox, & mut tests, ErrorCodes :: No , false , None ) ;
7491
7592 if tests. found_tests == 0 {
76- use ItemEnum :: * ;
77-
78- let should_report = match item. inner {
79- ExternCrateItem ( _, _) | ImportItem ( _) | PrimitiveItem ( _) | KeywordItem ( _) => false ,
80- _ => true ,
81- } ;
82- if should_report {
93+ if should_have_doc_example ( & item. inner ) {
8394 debug ! ( "reporting error for {:?} (hir_id={:?})" , item, hir_id) ;
8495 let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
8596 cx. tcx . struct_span_lint_hir (
0 commit comments