4
4
//! - PRIVATE_DOC_TESTS: this looks for private items with doc-tests.
5
5
6
6
use super :: { span_of_attrs, Pass } ;
7
+ use crate :: clean;
7
8
use crate :: clean:: * ;
8
9
use crate :: core:: DocContext ;
9
10
use crate :: fold:: DocFolder ;
@@ -59,6 +60,22 @@ impl crate::test::Tester for Tests {
59
60
}
60
61
}
61
62
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
+
62
79
pub fn look_for_tests < ' tcx > ( cx : & DocContext < ' tcx > , dox : & str , item : & Item ) {
63
80
let hir_id = match cx. as_local_hir_id ( item. def_id ) {
64
81
Some ( hir_id) => hir_id,
@@ -73,13 +90,7 @@ pub fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
73
90
find_testable_code ( & dox, & mut tests, ErrorCodes :: No , false , None ) ;
74
91
75
92
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 ) {
83
94
debug ! ( "reporting error for {:?} (hir_id={:?})" , item, hir_id) ;
84
95
let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
85
96
cx. tcx . struct_span_lint_hir (
0 commit comments