diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d0d92a1116f..892dfe4240b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -971,10 +971,8 @@ fn clean_ty_alias_inner_type<'tcx>( .map(|variant| clean_variant_def_with_args(variant, args, cx)) .collect(); - let has_stripped_variants = adt_def.variants().len() != variants.len(); TypeAliasInnerType::Enum { variants, - has_stripped_variants, is_non_exhaustive: adt_def.is_variant_list_non_exhaustive(), } } else { @@ -987,11 +985,10 @@ fn clean_ty_alias_inner_type<'tcx>( let fields: Vec<_> = clean_variant_def_with_args(variant, args, cx).kind.inner_items().cloned().collect(); - let has_stripped_fields = variant.fields.len() != fields.len(); if adt_def.is_struct() { - TypeAliasInnerType::Struct { ctor_kind: variant.ctor_kind(), fields, has_stripped_fields } + TypeAliasInnerType::Struct { ctor_kind: variant.ctor_kind(), fields } } else { - TypeAliasInnerType::Union { fields, has_stripped_fields } + TypeAliasInnerType::Union { fields } } }) } @@ -2415,7 +2412,6 @@ pub(crate) fn clean_variant_def_with_args<'tcx>( variant .fields .iter() - .filter(|field| field.vis.is_public()) .map(|field| { let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args); clean_field_with_def_id( @@ -2431,7 +2427,6 @@ pub(crate) fn clean_variant_def_with_args<'tcx>( fields: variant .fields .iter() - .filter(|field| field.vis.is_public()) .map(|field| { let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args); clean_field_with_def_id( diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 6efe4179707..9cc5d7c2911 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2231,20 +2231,9 @@ pub(crate) struct PathSegment { #[derive(Clone, Debug)] pub(crate) enum TypeAliasInnerType { - Enum { - variants: IndexVec, - has_stripped_variants: bool, - is_non_exhaustive: bool, - }, - Union { - fields: Vec, - has_stripped_fields: bool, - }, - Struct { - ctor_kind: Option, - fields: Vec, - has_stripped_fields: bool, - }, + Enum { variants: IndexVec, is_non_exhaustive: bool }, + Union { fields: Vec }, + Struct { ctor_kind: Option, fields: Vec }, } #[derive(Clone, Debug)] diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index ceba643ed5f..cf11e2d7899 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -52,10 +52,31 @@ fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind { VariantItem(Variant { kind, discriminant }) } + TypeAliasItem(mut typealias) => { + typealias.inner_type = typealias.inner_type.map(|inner_type| match inner_type { + TypeAliasInnerType::Enum { variants, is_non_exhaustive } => { + let variants = variants + .into_iter_enumerated() + .filter_map(|(_, x)| self.fold_item(x)) + .collect(); + + TypeAliasInnerType::Enum { variants, is_non_exhaustive } + } + TypeAliasInnerType::Union { fields } => { + let fields = fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); + TypeAliasInnerType::Union { fields } + } + TypeAliasInnerType::Struct { ctor_kind, fields } => { + let fields = fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); + TypeAliasInnerType::Struct { ctor_kind, fields } + } + }); + + TypeAliasItem(typealias) + } ExternCrateItem { src: _ } | ImportItem(_) | FunctionItem(_) - | TypeAliasItem(_) | OpaqueTyItem(_) | StaticItem(_) | ConstantItem(_) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 9a34e7cce8a..4c6e7dfb987 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -457,6 +457,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option { | clean::StructItem(..) | clean::UnionItem(..) | clean::VariantItem(..) + | clean::TypeAliasItem(..) | clean::ImplItem(..) => { self.cache.parent_stack.push(ParentStackItem::new(&item)); (self.fold_item_recur(item), true) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 09be756f26d..4f3a792fd7f 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1270,30 +1270,34 @@ fn toggle(w: &mut W, f: F) } match &t.inner_type { - Some(clean::TypeAliasInnerType::Enum { - variants, - has_stripped_variants: has_stripped_entries, - is_non_exhaustive, - }) => { + Some(clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive }) => { toggle(w, |w| { + let variants_iter = || variants.iter().filter(|i| !i.is_stripped()); wrap_item(w, |w| { + let variants_len = variants.len(); + let variants_count = variants_iter().count(); + let has_stripped_entries = variants_len != variants_count; + write!(w, "enum {}{}", it.name.unwrap(), t.generics.print(cx)); render_enum_fields( w, cx, None, - variants.iter(), - variants.len(), - *has_stripped_entries, + variants_iter(), + variants_count, + has_stripped_entries, *is_non_exhaustive, ) }); - item_variants(w, cx, it, variants.iter()); + item_variants(w, cx, it, variants_iter()); }); } - Some(clean::TypeAliasInnerType::Union { fields, has_stripped_fields }) => { + Some(clean::TypeAliasInnerType::Union { fields }) => { toggle(w, |w| { wrap_item(w, |w| { + let fields_count = fields.iter().filter(|i| !i.is_stripped()).count(); + let has_stripped_fields = fields.len() != fields_count; + write!(w, "union {}{}", it.name.unwrap(), t.generics.print(cx)); render_struct_fields( w, @@ -1302,16 +1306,19 @@ fn toggle(w: &mut W, f: F) fields, "", true, - *has_stripped_fields, + has_stripped_fields, cx, ); }); item_fields(w, cx, it, fields, None); }); } - Some(clean::TypeAliasInnerType::Struct { ctor_kind, fields, has_stripped_fields }) => { + Some(clean::TypeAliasInnerType::Struct { ctor_kind, fields }) => { toggle(w, |w| { wrap_item(w, |w| { + let fields_count = fields.iter().filter(|i| !i.is_stripped()).count(); + let has_stripped_fields = fields.len() != fields_count; + write!(w, "struct {}{}", it.name.unwrap(), t.generics.print(cx)); render_struct_fields( w, @@ -1320,7 +1327,7 @@ fn toggle(w: &mut W, f: F) fields, "", true, - *has_stripped_fields, + has_stripped_fields, cx, ); }); diff --git a/tests/rustdoc/typedef-inner-variants.rs b/tests/rustdoc/typedef-inner-variants.rs index 46acd86e12f..cb9c1248c46 100644 --- a/tests/rustdoc/typedef-inner-variants.rs +++ b/tests/rustdoc/typedef-inner-variants.rs @@ -22,6 +22,8 @@ pub enum IrTyKind { TyKind(A, B), // no comment StructKind { a: A, }, + #[doc(hidden)] + Unspecified, } // @has 'inner_variants/type.NearlyTyKind.html' @@ -52,7 +54,9 @@ pub union OneOr { // @has 'inner_variants/struct.One.html' pub struct One { pub val: T, - __hidden: T, + #[doc(hidden)] + pub __hidden: T, + __private: T, } // @has 'inner_variants/type.OneU64.html'