Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more Clean trait implementations #99950

Merged
merged 2 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use rustc_span::symbol::{kw, sym, Symbol};

use crate::clean::{
self, clean_fn_decl_from_did_and_sig, clean_middle_field, clean_middle_ty, clean_ty,
clean_ty_generics, clean_visibility, utils, Attributes, AttributesExt, Clean, ImplKind, ItemId,
Type, Visibility,
clean_ty_generics, clean_variant_def, clean_visibility, utils, Attributes, AttributesExt,
Clean, ImplKind, ItemId, Type, Visibility,
};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -236,7 +236,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {

clean::Enum {
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
variants: cx.tcx.adt_def(did).variants().iter().map(|v| v.clean(cx)).collect(),
variants: cx.tcx.adt_def(did).variants().iter().map(|v| clean_variant_def(v, cx)).collect(),
}
}

Expand Down
62 changes: 27 additions & 35 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,44 +1824,36 @@ pub(crate) fn clean_visibility(vis: ty::Visibility) -> Visibility {
}
}

pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
let kind = match variant.ctor_kind {
CtorKind::Const => Variant::CLike,
CtorKind::Fn => Variant::Tuple(
variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
),
CtorKind::Fictive => Variant::Struct(VariantStruct {
struct_type: CtorKind::Fictive,
fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
}),
};
let what_rustc_thinks =
Item::from_def_id_and_parts(variant.def_id, Some(variant.name), VariantItem(kind), cx);
// don't show `pub` for variants, which always inherit visibility
Item { visibility: Inherited, ..what_rustc_thinks }
}

fn clean_variant_data<'tcx>(
variant: &hir::VariantData<'tcx>,
cx: &mut DocContext<'tcx>,
) -> VariantStruct {
VariantStruct {
struct_type: CtorKind::from_hir(variant),
fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(),
}
}

impl<'tcx> Clean<'tcx, Item> for ty::VariantDef {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
let kind = match self.ctor_kind {
CtorKind::Const => Variant::CLike,
CtorKind::Fn => Variant::Tuple(
self.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
),
CtorKind::Fictive => Variant::Struct(VariantStruct {
struct_type: CtorKind::Fictive,
fields: self.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
}),
};
let what_rustc_thinks =
Item::from_def_id_and_parts(self.def_id, Some(self.name), VariantItem(kind), cx);
// don't show `pub` for variants, which always inherit visibility
Item { visibility: Inherited, ..what_rustc_thinks }
}
}

impl<'tcx> Clean<'tcx, Variant> for hir::VariantData<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Variant {
match self {
hir::VariantData::Struct(..) => Variant::Struct(clean_variant_data(self, cx)),
hir::VariantData::Tuple(..) => {
Variant::Tuple(self.fields().iter().map(|x| clean_field(x, cx)).collect())
}
hir::VariantData::Unit(..) => Variant::CLike,
) -> Variant {
match variant {
hir::VariantData::Struct(..) => Variant::Struct(VariantStruct {
struct_type: CtorKind::from_hir(variant),
fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
hir::VariantData::Tuple(..) => {
Variant::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect())
}
hir::VariantData::Unit(..) => Variant::CLike,
}
}

Expand Down Expand Up @@ -2009,7 +2001,7 @@ fn clean_maybe_renamed_item<'tcx>(

impl<'tcx> Clean<'tcx, Item> for hir::Variant<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
let kind = VariantItem(self.data.clean(cx));
let kind = VariantItem(clean_variant_data(&self.data, cx));
let what_rustc_thinks =
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
// don't show `pub` for variants, which are always public
Expand Down