From 21c812aa7a1a51a9583d7d90954079e9a21bc571 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 30 Jul 2022 17:34:29 +0200 Subject: [PATCH] Remove Clean trait implementation for ty::VariantDef --- src/librustdoc/clean/inline.rs | 6 +++--- src/librustdoc/clean/mod.rs | 32 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 55d77a63f61..838283e32da 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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; @@ -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(), } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 10676aca480..efd8cf5205b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1834,23 +1834,21 @@ fn clean_variant_data<'tcx>( } } -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 } - } +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 } } impl<'tcx> Clean<'tcx, Variant> for hir::VariantData<'tcx> {