1
Fork 0

Remove Clean impl for Vec<T>

This commit is contained in:
Noah Lev 2021-11-07 09:19:25 -08:00
parent efe4d7ca7e
commit 72b0a57244
3 changed files with 47 additions and 49 deletions

View file

@ -121,8 +121,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.tcx .tcx
.associated_items(impl_def_id) .associated_items(impl_def_id)
.in_definition_order() .in_definition_order()
.collect::<Vec<_>>() .map(|x| x.clean(self.cx))
.clean(self.cx), .collect::<Vec<_>>(),
polarity: ty::ImplPolarity::Positive, polarity: ty::ImplPolarity::Positive,
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)), kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)),
}), }),

View file

@ -255,7 +255,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
clean::Struct { clean::Struct {
struct_type: variant.ctor_kind, struct_type: variant.ctor_kind,
generics: (cx.tcx.generics_of(did), predicates).clean(cx), 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, 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 predicates = cx.tcx.explicit_predicates_of(did);
let variant = cx.tcx.adt_def(did).non_enum_variant(); let variant = cx.tcx.adt_def(did).non_enum_variant();
clean::Union { let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
generics: (cx.tcx.generics_of(did), predicates).clean(cx), let fields = variant.fields.iter().map(|x| x.clean(cx)).collect();
fields: variant.fields.clean(cx), clean::Union { generics, fields, fields_stripped: false }
fields_stripped: false,
}
} }
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef {

View file

@ -55,12 +55,6 @@ crate trait Clean<T> {
fn clean(&self, cx: &mut DocContext<'_>) -> T; fn clean(&self, cx: &mut DocContext<'_>) -> T;
} }
impl<T: Clean<U>, U> Clean<Vec<U>> for [T] {
fn clean(&self, cx: &mut DocContext<'_>) -> Vec<U> {
self.iter().map(|x| x.clean(cx)).collect()
}
}
impl<T: Clean<U>, U> Clean<U> for &T { impl<T: Clean<U>, U> Clean<U> for &T {
fn clean(&self, cx: &mut DocContext<'_>) -> U { fn clean(&self, cx: &mut DocContext<'_>) -> U {
(**self).clean(cx) (**self).clean(cx)
@ -274,14 +268,14 @@ impl Clean<WherePredicate> for hir::WherePredicate<'_> {
.collect(); .collect();
WherePredicate::BoundPredicate { WherePredicate::BoundPredicate {
ty: wbp.bounded_ty.clean(cx), ty: wbp.bounded_ty.clean(cx),
bounds: wbp.bounds.clean(cx), bounds: wbp.bounds.iter().map(|x| x.clean(cx)).collect(),
bound_params, bound_params,
} }
} }
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate { hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
lifetime: wrp.lifetime.clean(cx), 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) => { hir::WherePredicate::EqPredicate(ref wrp) => {
@ -446,7 +440,7 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
self.name.ident().name, self.name.ident().name,
GenericParamDefKind::Type { GenericParamDefKind::Type {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(), 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), default: default.map(|t| t.clean(cx)).map(Box::new),
synthetic, synthetic,
}, },
@ -517,8 +511,10 @@ impl Clean<Generics> for hir::Generics<'_> {
} }
params.extend(impl_trait_params); params.extend(impl_trait_params);
let mut generics = let mut generics = Generics {
Generics { params, where_predicates: self.where_clause.predicates.clean(cx) }; 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 // 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 // predicates. The point in here is to move the bounds definitions from type params
@ -887,7 +883,7 @@ impl Clean<PolyTrait> for hir::PolyTraitRef<'_> {
fn clean(&self, cx: &mut DocContext<'_>) -> PolyTrait { fn clean(&self, cx: &mut DocContext<'_>) -> PolyTrait {
PolyTrait { PolyTrait {
trait_: self.trait_ref.clean(cx), 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<Item> for hir::TraitItem<'_> {
TyMethodItem(t) TyMethodItem(t)
} }
hir::TraitItemKind::Type(bounds, ref default) => { 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 = 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_def = cx.tcx.associated_item(p.res.def_id()).container.id();
let trait_ = self::Path { let trait_ = self::Path {
res: Res::Def(DefKind::Trait, trait_def), 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); register_res(cx, trait_.res);
Type::QPath { Type::QPath {
@ -1322,11 +1320,11 @@ impl Clean<Type> for hir::Ty<'_> {
let length = print_const(cx, ct.eval(cx.tcx, param_env)); let length = print_const(cx, ct.eval(cx.tcx, param_env));
Array(box ty.clean(cx), length) 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, _) => { TyKind::OpaqueDef(item_id, _) => {
let item = cx.tcx.hir().item(item_id); let item = cx.tcx.hir().item(item_id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { 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 { } else {
unreachable!() unreachable!()
} }
@ -1466,7 +1464,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
DynTrait(bounds, lifetime) DynTrait(bounds, lifetime)
} }
ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx)), ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty().clean(cx)).collect()),
ty::Projection(ref data) => data.clean(cx), ty::Projection(ref data) => data.clean(cx),
@ -1699,7 +1697,7 @@ impl Clean<Variant> for hir::VariantData<'_> {
impl Clean<Path> for hir::Path<'_> { impl Clean<Path> for hir::Path<'_> {
fn clean(&self, cx: &mut DocContext<'_>) -> 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<GenericArgs> for hir::GenericArgs<'_> {
let output = self.bindings[0].ty().clean(cx); let output = self.bindings[0].ty().clean(cx);
let output = let output =
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None }; 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 { } else {
GenericArgs::AngleBracketed { let args = self
args: self .args
.args .iter()
.iter() .map(|arg| match arg {
.map(|arg| match arg { hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { GenericArg::Lifetime(lt.clean(cx))
GenericArg::Lifetime(lt.clean(cx)) }
} hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)),
hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))), hir::GenericArg::Infer(_inf) => GenericArg::Infer,
hir::GenericArg::Infer(_inf) => GenericArg::Infer, })
}) .collect();
.collect(), let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect();
bindings: self.bindings.clean(cx), GenericArgs::AngleBracketed { args, bindings }
}
} }
} }
} }
@ -1740,7 +1738,9 @@ impl Clean<PathSegment> for hir::PathSegment<'_> {
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> { impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl { fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl {
let (generic_params, decl) = enter_impl_trait(cx, |cx| { 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 } BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
} }
@ -1763,7 +1763,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
kind: ConstantKind::Local { body: body_id, def_id }, kind: ConstantKind::Local { body: body_id, def_id },
}), }),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { 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), generics: ty.generics.clean(cx),
}), }),
ItemKind::TyAlias(hir_ty, ref generics) => { ItemKind::TyAlias(hir_ty, ref generics) => {
@ -1785,17 +1785,17 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
}), }),
ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias { ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias {
generics: generics.clean(cx), 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 { ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union {
generics: generics.clean(cx), generics: generics.clean(cx),
fields: variant_data.fields().clean(cx), fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
fields_stripped: false, fields_stripped: false,
}), }),
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct { ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
struct_type: CtorKind::from_hir(variant_data), struct_type: CtorKind::from_hir(variant_data),
generics: generics.clean(cx), generics: generics.clean(cx),
fields: variant_data.fields().clean(cx), fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
fields_stripped: false, fields_stripped: false,
}), }),
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx), ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
@ -1815,7 +1815,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
unsafety, unsafety,
items, items,
generics: generics.clean(cx), generics: generics.clean(cx),
bounds: bounds.clean(cx), bounds: bounds.iter().map(|x| x.clean(cx)).collect(),
is_auto: is_auto.clean(cx), is_auto: is_auto.clean(cx),
}) })
} }