rustdoc: bind typedef inner type items to the folding system
This let's us handle a multitude of things for free: - #[doc(hidden)] - private fields/variants - --document-private-items - --document-hidden-items And correct in the process the determination of "has stripped items" by doing the same logic done by other ones.
This commit is contained in:
parent
6b3bba8c3e
commit
af6889c28c
@ -971,10 +971,8 @@ fn clean_ty_alias_inner_type<'tcx>(
|
|||||||
.map(|variant| clean_variant_def_with_args(variant, args, cx))
|
.map(|variant| clean_variant_def_with_args(variant, args, cx))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let has_stripped_variants = adt_def.variants().len() != variants.len();
|
|
||||||
TypeAliasInnerType::Enum {
|
TypeAliasInnerType::Enum {
|
||||||
variants,
|
variants,
|
||||||
has_stripped_variants,
|
|
||||||
is_non_exhaustive: adt_def.is_variant_list_non_exhaustive(),
|
is_non_exhaustive: adt_def.is_variant_list_non_exhaustive(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -987,11 +985,10 @@ fn clean_ty_alias_inner_type<'tcx>(
|
|||||||
let fields: Vec<_> =
|
let fields: Vec<_> =
|
||||||
clean_variant_def_with_args(variant, args, cx).kind.inner_items().cloned().collect();
|
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() {
|
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 {
|
} else {
|
||||||
TypeAliasInnerType::Union { fields, has_stripped_fields }
|
TypeAliasInnerType::Union { fields }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2415,7 +2412,6 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
|
|||||||
variant
|
variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|field| field.vis.is_public())
|
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
|
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
|
||||||
clean_field_with_def_id(
|
clean_field_with_def_id(
|
||||||
@ -2431,7 +2427,6 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
|
|||||||
fields: variant
|
fields: variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|field| field.vis.is_public())
|
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
|
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
|
||||||
clean_field_with_def_id(
|
clean_field_with_def_id(
|
||||||
|
@ -2231,20 +2231,9 @@ pub(crate) struct PathSegment {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) enum TypeAliasInnerType {
|
pub(crate) enum TypeAliasInnerType {
|
||||||
Enum {
|
Enum { variants: IndexVec<VariantIdx, Item>, is_non_exhaustive: bool },
|
||||||
variants: IndexVec<VariantIdx, Item>,
|
Union { fields: Vec<Item> },
|
||||||
has_stripped_variants: bool,
|
Struct { ctor_kind: Option<CtorKind>, fields: Vec<Item> },
|
||||||
is_non_exhaustive: bool,
|
|
||||||
},
|
|
||||||
Union {
|
|
||||||
fields: Vec<Item>,
|
|
||||||
has_stripped_fields: bool,
|
|
||||||
},
|
|
||||||
Struct {
|
|
||||||
ctor_kind: Option<CtorKind>,
|
|
||||||
fields: Vec<Item>,
|
|
||||||
has_stripped_fields: bool,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -52,10 +52,31 @@ fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind {
|
|||||||
|
|
||||||
VariantItem(Variant { kind, discriminant })
|
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: _ }
|
ExternCrateItem { src: _ }
|
||||||
| ImportItem(_)
|
| ImportItem(_)
|
||||||
| FunctionItem(_)
|
| FunctionItem(_)
|
||||||
| TypeAliasItem(_)
|
|
||||||
| OpaqueTyItem(_)
|
| OpaqueTyItem(_)
|
||||||
| StaticItem(_)
|
| StaticItem(_)
|
||||||
| ConstantItem(_)
|
| ConstantItem(_)
|
||||||
|
@ -457,6 +457,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
|
|||||||
| clean::StructItem(..)
|
| clean::StructItem(..)
|
||||||
| clean::UnionItem(..)
|
| clean::UnionItem(..)
|
||||||
| clean::VariantItem(..)
|
| clean::VariantItem(..)
|
||||||
|
| clean::TypeAliasItem(..)
|
||||||
| clean::ImplItem(..) => {
|
| clean::ImplItem(..) => {
|
||||||
self.cache.parent_stack.push(ParentStackItem::new(&item));
|
self.cache.parent_stack.push(ParentStackItem::new(&item));
|
||||||
(self.fold_item_recur(item), true)
|
(self.fold_item_recur(item), true)
|
||||||
|
@ -1270,30 +1270,34 @@ fn toggle<W, F>(w: &mut W, f: F)
|
|||||||
}
|
}
|
||||||
|
|
||||||
match &t.inner_type {
|
match &t.inner_type {
|
||||||
Some(clean::TypeAliasInnerType::Enum {
|
Some(clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive }) => {
|
||||||
variants,
|
|
||||||
has_stripped_variants: has_stripped_entries,
|
|
||||||
is_non_exhaustive,
|
|
||||||
}) => {
|
|
||||||
toggle(w, |w| {
|
toggle(w, |w| {
|
||||||
|
let variants_iter = || variants.iter().filter(|i| !i.is_stripped());
|
||||||
wrap_item(w, |w| {
|
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));
|
write!(w, "enum {}{}", it.name.unwrap(), t.generics.print(cx));
|
||||||
render_enum_fields(
|
render_enum_fields(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
None,
|
None,
|
||||||
variants.iter(),
|
variants_iter(),
|
||||||
variants.len(),
|
variants_count,
|
||||||
*has_stripped_entries,
|
has_stripped_entries,
|
||||||
*is_non_exhaustive,
|
*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| {
|
toggle(w, |w| {
|
||||||
wrap_item(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));
|
write!(w, "union {}{}", it.name.unwrap(), t.generics.print(cx));
|
||||||
render_struct_fields(
|
render_struct_fields(
|
||||||
w,
|
w,
|
||||||
@ -1302,16 +1306,19 @@ fn toggle<W, F>(w: &mut W, f: F)
|
|||||||
fields,
|
fields,
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
*has_stripped_fields,
|
has_stripped_fields,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
item_fields(w, cx, it, fields, None);
|
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| {
|
toggle(w, |w| {
|
||||||
wrap_item(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));
|
write!(w, "struct {}{}", it.name.unwrap(), t.generics.print(cx));
|
||||||
render_struct_fields(
|
render_struct_fields(
|
||||||
w,
|
w,
|
||||||
@ -1320,7 +1327,7 @@ fn toggle<W, F>(w: &mut W, f: F)
|
|||||||
fields,
|
fields,
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
*has_stripped_fields,
|
has_stripped_fields,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,8 @@ pub enum IrTyKind<A, B> {
|
|||||||
TyKind(A, B),
|
TyKind(A, B),
|
||||||
// no comment
|
// no comment
|
||||||
StructKind { a: A, },
|
StructKind { a: A, },
|
||||||
|
#[doc(hidden)]
|
||||||
|
Unspecified,
|
||||||
}
|
}
|
||||||
|
|
||||||
// @has 'inner_variants/type.NearlyTyKind.html'
|
// @has 'inner_variants/type.NearlyTyKind.html'
|
||||||
@ -52,7 +54,9 @@ pub union OneOr<A: Copy> {
|
|||||||
// @has 'inner_variants/struct.One.html'
|
// @has 'inner_variants/struct.One.html'
|
||||||
pub struct One<T> {
|
pub struct One<T> {
|
||||||
pub val: T,
|
pub val: T,
|
||||||
__hidden: T,
|
#[doc(hidden)]
|
||||||
|
pub __hidden: T,
|
||||||
|
__private: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
// @has 'inner_variants/type.OneU64.html'
|
// @has 'inner_variants/type.OneU64.html'
|
||||||
|
Loading…
Reference in New Issue
Block a user