Skip to content

Commit 404782d

Browse files
authored
Rollup merge of #100166 - GuillaumeGomez:rm-clean-impls, r=Dylan-DPC
Remove more Clean trait implementations Follow-up of #99638. r? `@notriddle`
2 parents 823ef90 + 46d17d6 commit 404782d

File tree

1 file changed

+65
-64
lines changed

1 file changed

+65
-64
lines changed

src/librustdoc/clean/mod.rs

+65-64
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
156156
return None;
157157
}
158158

159-
GenericBound::TraitBound(t.clean(cx), modifier)
159+
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
160160
}
161161
})
162162
}
@@ -1001,69 +1001,68 @@ fn clean_trait_ref<'tcx>(trait_ref: &hir::TraitRef<'tcx>, cx: &mut DocContext<'t
10011001
path
10021002
}
10031003

1004-
impl<'tcx> Clean<'tcx, PolyTrait> for hir::PolyTraitRef<'tcx> {
1005-
fn clean(&self, cx: &mut DocContext<'tcx>) -> PolyTrait {
1006-
PolyTrait {
1007-
trait_: clean_trait_ref(&self.trait_ref, cx),
1008-
generic_params: self
1009-
.bound_generic_params
1010-
.iter()
1011-
.filter(|p| !is_elided_lifetime(p))
1012-
.map(|x| clean_generic_param(cx, None, x))
1013-
.collect(),
1014-
}
1004+
fn clean_poly_trait_ref<'tcx>(
1005+
poly_trait_ref: &hir::PolyTraitRef<'tcx>,
1006+
cx: &mut DocContext<'tcx>,
1007+
) -> PolyTrait {
1008+
PolyTrait {
1009+
trait_: clean_trait_ref(&poly_trait_ref.trait_ref, cx),
1010+
generic_params: poly_trait_ref
1011+
.bound_generic_params
1012+
.iter()
1013+
.filter(|p| !is_elided_lifetime(p))
1014+
.map(|x| clean_generic_param(cx, None, x))
1015+
.collect(),
10151016
}
10161017
}
10171018

1018-
impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
1019-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
1020-
let local_did = self.def_id.to_def_id();
1021-
cx.with_param_env(local_did, |cx| {
1022-
let inner = match self.kind {
1023-
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
1024-
clean_ty(ty, cx),
1025-
ConstantKind::Local { def_id: local_did, body: default },
1026-
),
1027-
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(clean_ty(ty, cx)),
1028-
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1029-
let m = clean_function(cx, sig, self.generics, body);
1030-
MethodItem(m, None)
1031-
}
1032-
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
1033-
let (generics, decl) = enter_impl_trait(cx, |cx| {
1034-
// NOTE: generics must be cleaned before args
1035-
let generics = self.generics.clean(cx);
1036-
let args = clean_args_from_types_and_names(cx, sig.decl.inputs, names);
1037-
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
1038-
(generics, decl)
1039-
});
1040-
TyMethodItem(Box::new(Function { decl, generics }))
1041-
}
1042-
hir::TraitItemKind::Type(bounds, Some(default)) => {
1043-
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
1044-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1045-
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
1046-
AssocTypeItem(
1047-
Box::new(Typedef {
1048-
type_: clean_ty(default, cx),
1049-
generics,
1050-
item_type: Some(item_type),
1051-
}),
1052-
bounds,
1053-
)
1054-
}
1055-
hir::TraitItemKind::Type(bounds, None) => {
1056-
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
1057-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1058-
TyAssocTypeItem(Box::new(generics), bounds)
1059-
}
1060-
};
1061-
let what_rustc_thinks =
1062-
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx);
1063-
// Trait items always inherit the trait's visibility -- we don't want to show `pub`.
1064-
Item { visibility: Inherited, ..what_rustc_thinks }
1065-
})
1066-
}
1019+
fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
1020+
let local_did = trait_item.def_id.to_def_id();
1021+
cx.with_param_env(local_did, |cx| {
1022+
let inner = match trait_item.kind {
1023+
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
1024+
clean_ty(ty, cx),
1025+
ConstantKind::Local { def_id: local_did, body: default },
1026+
),
1027+
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(clean_ty(ty, cx)),
1028+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1029+
let m = clean_function(cx, sig, trait_item.generics, body);
1030+
MethodItem(m, None)
1031+
}
1032+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
1033+
let (generics, decl) = enter_impl_trait(cx, |cx| {
1034+
// NOTE: generics must be cleaned before args
1035+
let generics = trait_item.generics.clean(cx);
1036+
let args = clean_args_from_types_and_names(cx, sig.decl.inputs, names);
1037+
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
1038+
(generics, decl)
1039+
});
1040+
TyMethodItem(Box::new(Function { decl, generics }))
1041+
}
1042+
hir::TraitItemKind::Type(bounds, Some(default)) => {
1043+
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1044+
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1045+
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
1046+
AssocTypeItem(
1047+
Box::new(Typedef {
1048+
type_: clean_ty(default, cx),
1049+
generics,
1050+
item_type: Some(item_type),
1051+
}),
1052+
bounds,
1053+
)
1054+
}
1055+
hir::TraitItemKind::Type(bounds, None) => {
1056+
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1057+
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1058+
TyAssocTypeItem(Box::new(generics), bounds)
1059+
}
1060+
};
1061+
let what_rustc_thinks =
1062+
Item::from_def_id_and_parts(local_did, Some(trait_item.ident.name), inner, cx);
1063+
// Trait items always inherit the trait's visibility -- we don't want to show `pub`.
1064+
Item { visibility: Inherited, ..what_rustc_thinks }
1065+
})
10671066
}
10681067

10691068
impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
@@ -1515,7 +1514,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15151514
}
15161515
TyKind::Path(_) => clean_qpath(ty, cx),
15171516
TyKind::TraitObject(bounds, ref lifetime, _) => {
1518-
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
1517+
let bounds = bounds.iter().map(|bound| clean_poly_trait_ref(bound, cx)).collect();
15191518
let lifetime =
15201519
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
15211520
DynTrait(bounds, lifetime)
@@ -1953,8 +1952,10 @@ fn clean_maybe_renamed_item<'tcx>(
19531952
})
19541953
}
19551954
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
1956-
let items =
1957-
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
1955+
let items = item_ids
1956+
.iter()
1957+
.map(|ti| clean_trait_item(cx.tcx.hir().trait_item(ti.id), cx))
1958+
.collect();
19581959

19591960
TraitItem(Trait {
19601961
def_id,

0 commit comments

Comments
 (0)