@@ -10,6 +10,7 @@ use crate::core::DocContext;
1010use crate :: fold:: DocFolder ;
1111use crate :: html:: markdown:: { find_testable_code, ErrorCodes , Ignore , LangString } ;
1212use crate :: visit_ast:: inherits_doc_hidden;
13+ use rustc_hir as hir;
1314use rustc_middle:: lint:: LintLevelSource ;
1415use rustc_session:: lint;
1516use rustc_span:: symbol:: sym;
@@ -67,13 +68,32 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
6768 | clean:: ImportItem ( _)
6869 | clean:: PrimitiveItem ( _)
6970 | clean:: KeywordItem ( _)
71+ // check for trait impl
72+ | clean:: ImplItem ( clean:: Impl { trait_: Some ( _) , .. } )
7073 )
7174 {
7275 return false ;
7376 }
77+
7478 // The `expect_def_id()` should be okay because `local_def_id_to_hir_id`
7579 // would presumably panic if a fake `DefIndex` were passed.
7680 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+
7797 if cx. tcx . hir ( ) . attrs ( hir_id) . lists ( sym:: doc) . has_word ( sym:: hidden)
7898 || inherits_doc_hidden ( cx. tcx , hir_id)
7999 {
0 commit comments