File tree Expand file tree Collapse file tree 3 files changed +59
-4
lines changed Expand file tree Collapse file tree 3 files changed +59
-4
lines changed Original file line number Diff line number Diff line change @@ -425,13 +425,26 @@ crate fn build_impl(
425425 None => (
426426 tcx. associated_items ( did)
427427 . in_definition_order ( )
428- . filter_map ( |item| {
429- if associated_trait. is_some ( ) || item. vis . is_public ( ) {
430- Some ( item. clean ( cx) )
428+ . filter ( |item| {
429+ // If this is a trait impl, filter out associated items whose corresponding item
430+ // in the associated trait is marked `doc(hidden)`.
431+ // If this is an inherent impl, filter out private associated items.
432+ if let Some ( associated_trait) = associated_trait {
433+ let trait_item = tcx
434+ . associated_items ( associated_trait. def_id )
435+ . find_by_name_and_kind (
436+ tcx,
437+ item. ident ( tcx) ,
438+ item. kind ,
439+ associated_trait. def_id ,
440+ )
441+ . unwrap ( ) ; // corresponding associated item has to exist
442+ !tcx. is_doc_hidden ( trait_item. def_id )
431443 } else {
432- None
444+ item . vis . is_public ( )
433445 }
434446 } )
447+ . map ( |item| item. clean ( cx) )
435448 . collect :: < Vec < _ > > ( ) ,
436449 clean:: enter_impl_trait ( cx, |cx| {
437450 clean_ty_generics ( cx, tcx. generics_of ( did) , predicates)
Original file line number Diff line number Diff line change 1+ pub trait Tr {
2+ type VisibleAssoc ;
3+ #[ doc( hidden) ]
4+ type HiddenAssoc ;
5+
6+ const VISIBLE_ASSOC : ( ) ;
7+ #[ doc( hidden) ]
8+ const HIDDEN_ASSOC : ( ) ;
9+ }
10+
11+ pub struct Ty ;
12+
13+ impl Tr for Ty {
14+ type VisibleAssoc = ( ) ;
15+ type HiddenAssoc = ( ) ;
16+
17+ const VISIBLE_ASSOC : ( ) = ( ) ;
18+ const HIDDEN_ASSOC : ( ) = ( ) ;
19+ }
Original file line number Diff line number Diff line change 1+ // Regression test for issue #95717
2+ // Hide cross-crate `#[doc(hidden)]` associated items in trait impls.
3+
4+ #![ crate_name = "dependent" ]
5+ // edition:2021
6+ // aux-crate:dependency=cross-crate-hidden-assoc-trait-items.rs
7+
8+ // The trait `Tr` contains 2 hidden and 2 visisible associated items.
9+ // Instead of checking for the absence of the hidden items, check for the presence of the
10+ // visible items instead and assert that there are *exactly two* associated items
11+ // (by counting the number of `section`s). This is more robust and future-proof.
12+
13+ // @has dependent/struct.Ty.html
14+ // @has - '//*[@id="associatedtype.VisibleAssoc"]' 'type VisibleAssoc = ()'
15+ // @has - '//*[@id="associatedconstant.VISIBLE_ASSOC"]' 'const VISIBLE_ASSOC: ()'
16+ // @count - '//*[@class="impl-items"]/section' 2
17+
18+ // @has dependent/trait.Tr.html
19+ // @has - '//*[@id="associatedtype.VisibleAssoc-1"]' 'type VisibleAssoc = ()'
20+ // @has - '//*[@id="associatedconstant.VISIBLE_ASSOC-1"]' 'const VISIBLE_ASSOC: ()'
21+ // @count - '//*[@class="impl-items"]/section' 2
22+
23+ pub use dependency:: { Tr , Ty } ;
You can’t perform that action at this time.
0 commit comments