@@ -10,6 +10,7 @@ use crate::core::DocContext;
10
10
use crate :: fold:: DocFolder ;
11
11
use crate :: html:: markdown:: { find_testable_code, ErrorCodes , Ignore , LangString } ;
12
12
use crate :: visit_ast:: inherits_doc_hidden;
13
+ use rustc_hir as hir;
13
14
use rustc_middle:: lint:: LintLevelSource ;
14
15
use rustc_session:: lint;
15
16
use rustc_span:: symbol:: sym;
@@ -67,13 +68,32 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
67
68
| clean:: ImportItem ( _)
68
69
| clean:: PrimitiveItem ( _)
69
70
| clean:: KeywordItem ( _)
71
+ // check for trait impl
72
+ | clean:: ImplItem ( clean:: Impl { trait_: Some ( _) , .. } )
70
73
)
71
74
{
72
75
return false ;
73
76
}
77
+
74
78
// The `expect_def_id()` should be okay because `local_def_id_to_hir_id`
75
79
// would presumably panic if a fake `DefIndex` were passed.
76
80
let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( item. def_id . expect_def_id ( ) . expect_local ( ) ) ;
81
+
82
+ // check if parent is trait impl
83
+ if let Some ( parent_hir_id) = cx. tcx . hir ( ) . find_parent_node ( hir_id) {
84
+ if let Some ( parent_node) = cx. tcx . hir ( ) . find ( parent_hir_id) {
85
+ if matches ! (
86
+ parent_node,
87
+ hir:: Node :: Item ( hir:: Item {
88
+ kind: hir:: ItemKind :: Impl ( hir:: Impl { of_trait: Some ( _) , .. } ) ,
89
+ ..
90
+ } )
91
+ ) {
92
+ return false ;
93
+ }
94
+ }
95
+ }
96
+
77
97
if cx. tcx . hir ( ) . attrs ( hir_id) . lists ( sym:: doc) . has_word ( sym:: hidden)
78
98
|| inherits_doc_hidden ( cx. tcx , hir_id)
79
99
{
0 commit comments