From 72b0a572448a0bea78bb560a2ec890463cb4532b Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 7 Nov 2021 09:19:25 -0800 Subject: [PATCH] Remove Clean impl for `Vec` --- src/librustdoc/clean/blanket_impl.rs | 4 +- src/librustdoc/clean/inline.rs | 10 ++-- src/librustdoc/clean/mod.rs | 82 ++++++++++++++-------------- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 433094e4ee4..f44589f6067 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -121,8 +121,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .tcx .associated_items(impl_def_id) .in_definition_order() - .collect::>() - .clean(self.cx), + .map(|x| x.clean(self.cx)) + .collect::>(), polarity: ty::ImplPolarity::Positive, kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)), }), diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 77f7f64b80b..d670288270a 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -255,7 +255,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct { clean::Struct { struct_type: variant.ctor_kind, generics: (cx.tcx.generics_of(did), predicates).clean(cx), - fields: variant.fields.clean(cx), + fields: variant.fields.iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, } } @@ -264,11 +264,9 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union { let predicates = cx.tcx.explicit_predicates_of(did); let variant = cx.tcx.adt_def(did).non_enum_variant(); - clean::Union { - generics: (cx.tcx.generics_of(did), predicates).clean(cx), - fields: variant.fields.clean(cx), - fields_stripped: false, - } + let generics = (cx.tcx.generics_of(did), predicates).clean(cx); + let fields = variant.fields.iter().map(|x| x.clean(cx)).collect(); + clean::Union { generics, fields, fields_stripped: false } } fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b5e15dd1820..8f2609efc55 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -55,12 +55,6 @@ crate trait Clean { fn clean(&self, cx: &mut DocContext<'_>) -> T; } -impl, U> Clean> for [T] { - fn clean(&self, cx: &mut DocContext<'_>) -> Vec { - self.iter().map(|x| x.clean(cx)).collect() - } -} - impl, U> Clean for &T { fn clean(&self, cx: &mut DocContext<'_>) -> U { (**self).clean(cx) @@ -274,14 +268,14 @@ impl Clean for hir::WherePredicate<'_> { .collect(); WherePredicate::BoundPredicate { ty: wbp.bounded_ty.clean(cx), - bounds: wbp.bounds.clean(cx), + bounds: wbp.bounds.iter().map(|x| x.clean(cx)).collect(), bound_params, } } hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate { lifetime: wrp.lifetime.clean(cx), - bounds: wrp.bounds.clean(cx), + bounds: wrp.bounds.iter().map(|x| x.clean(cx)).collect(), }, hir::WherePredicate::EqPredicate(ref wrp) => { @@ -446,7 +440,7 @@ impl Clean for hir::GenericParam<'_> { self.name.ident().name, GenericParamDefKind::Type { did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(), - bounds: self.bounds.clean(cx), + bounds: self.bounds.iter().map(|x| x.clean(cx)).collect(), default: default.map(|t| t.clean(cx)).map(Box::new), synthetic, }, @@ -517,8 +511,10 @@ impl Clean for hir::Generics<'_> { } params.extend(impl_trait_params); - let mut generics = - Generics { params, where_predicates: self.where_clause.predicates.clean(cx) }; + let mut generics = Generics { + params, + where_predicates: self.where_clause.predicates.iter().map(|x| x.clean(cx)).collect(), + }; // Some duplicates are generated for ?Sized bounds between type params and where // predicates. The point in here is to move the bounds definitions from type params @@ -887,7 +883,7 @@ impl Clean for hir::PolyTraitRef<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> PolyTrait { PolyTrait { trait_: self.trait_ref.clean(cx), - generic_params: self.bound_generic_params.clean(cx), + generic_params: self.bound_generic_params.iter().map(|x| x.clean(cx)).collect(), } } } @@ -922,7 +918,9 @@ impl Clean for hir::TraitItem<'_> { TyMethodItem(t) } hir::TraitItemKind::Type(bounds, ref default) => { - AssocTypeItem(bounds.clean(cx), default.map(|t| t.clean(cx))) + let bounds = bounds.iter().map(|x| x.clean(cx)).collect(); + let default = default.map(|t| t.clean(cx)); + AssocTypeItem(bounds, default) } }; let what_rustc_thinks = @@ -1256,7 +1254,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type { let trait_def = cx.tcx.associated_item(p.res.def_id()).container.id(); let trait_ = self::Path { res: Res::Def(DefKind::Trait, trait_def), - segments: trait_segments.clean(cx), + segments: trait_segments.iter().map(|x| x.clean(cx)).collect(), }; register_res(cx, trait_.res); Type::QPath { @@ -1322,11 +1320,11 @@ impl Clean for hir::Ty<'_> { let length = print_const(cx, ct.eval(cx.tcx, param_env)); Array(box ty.clean(cx), length) } - TyKind::Tup(tys) => Tuple(tys.clean(cx)), + TyKind::Tup(tys) => Tuple(tys.iter().map(|x| x.clean(cx)).collect()), TyKind::OpaqueDef(item_id, _) => { let item = cx.tcx.hir().item(item_id); if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { - ImplTrait(ty.bounds.clean(cx)) + ImplTrait(ty.bounds.iter().map(|x| x.clean(cx)).collect()) } else { unreachable!() } @@ -1466,7 +1464,7 @@ impl<'tcx> Clean for Ty<'tcx> { DynTrait(bounds, lifetime) } - ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty()).collect::>().clean(cx)), + ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty().clean(cx)).collect()), ty::Projection(ref data) => data.clean(cx), @@ -1699,7 +1697,7 @@ impl Clean for hir::VariantData<'_> { impl Clean for hir::Path<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> Path { - Path { res: self.res, segments: self.segments.clean(cx) } + Path { res: self.res, segments: self.segments.iter().map(|x| x.clean(cx)).collect() } } } @@ -1709,24 +1707,24 @@ impl Clean for hir::GenericArgs<'_> { let output = self.bindings[0].ty().clean(cx); let output = if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None }; - GenericArgs::Parenthesized { inputs: self.inputs().clean(cx), output } + let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect(); + GenericArgs::Parenthesized { inputs, output } } else { - GenericArgs::AngleBracketed { - args: self - .args - .iter() - .map(|arg| match arg { - hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { - GenericArg::Lifetime(lt.clean(cx)) - } - hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), - hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), - hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))), - hir::GenericArg::Infer(_inf) => GenericArg::Infer, - }) - .collect(), - bindings: self.bindings.clean(cx), - } + let args = self + .args + .iter() + .map(|arg| match arg { + hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { + GenericArg::Lifetime(lt.clean(cx)) + } + hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), + hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), + hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))), + hir::GenericArg::Infer(_inf) => GenericArg::Infer, + }) + .collect(); + let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect(); + GenericArgs::AngleBracketed { args, bindings } } } } @@ -1740,7 +1738,9 @@ impl Clean for hir::PathSegment<'_> { impl Clean for hir::BareFnTy<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl { let (generic_params, decl) = enter_impl_trait(cx, |cx| { - (self.generic_params.clean(cx), (&*self.decl, self.param_names).clean(cx)) + let generic_params = self.generic_params.iter().map(|x| x.clean(cx)).collect(); + let decl = (self.decl, self.param_names).clean(cx); + (generic_params, decl) }); BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params } } @@ -1763,7 +1763,7 @@ impl Clean> for (&hir::Item<'_>, Option) { kind: ConstantKind::Local { body: body_id, def_id }, }), ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { - bounds: ty.bounds.clean(cx), + bounds: ty.bounds.iter().map(|x| x.clean(cx)).collect(), generics: ty.generics.clean(cx), }), ItemKind::TyAlias(hir_ty, ref generics) => { @@ -1785,17 +1785,17 @@ impl Clean> for (&hir::Item<'_>, Option) { }), ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias { generics: generics.clean(cx), - bounds: bounds.clean(cx), + bounds: bounds.iter().map(|x| x.clean(cx)).collect(), }), ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union { generics: generics.clean(cx), - fields: variant_data.fields().clean(cx), + fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, }), ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct { struct_type: CtorKind::from_hir(variant_data), generics: generics.clean(cx), - fields: variant_data.fields().clean(cx), + fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, }), ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx), @@ -1815,7 +1815,7 @@ impl Clean> for (&hir::Item<'_>, Option) { unsafety, items, generics: generics.clean(cx), - bounds: bounds.clean(cx), + bounds: bounds.iter().map(|x| x.clean(cx)).collect(), is_auto: is_auto.clean(cx), }) }