mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #90750 - camelid:rm-tuple-impls-1, r=jyn514
rustdoc: Replace where-bounded Clean impl with simple function This is the first step in removing the Clean impls for tuples. Either way, this significantly simplifies the code since it reduces the amount of "trait magic". (To clarify, I'm referring to impls like `impl Clean for (A, B)`, not Clean impls that work on tuples in the user's program.) cc ``@jyn514``
This commit is contained in:
commit
47c1bd1bcc
@ -229,6 +229,7 @@ fn build_external_function(cx: &mut DocContext<'_>, did: DefId) -> clean::Functi
|
||||
let asyncness = cx.tcx.asyncness(did);
|
||||
let predicates = cx.tcx.predicates_of(did);
|
||||
let (generics, decl) = clean::enter_impl_trait(cx, |cx| {
|
||||
// NOTE: generics need to be cleaned before the decl!
|
||||
((cx.tcx.generics_of(did), predicates).clean(cx), (did, sig).clean(cx))
|
||||
});
|
||||
clean::Function {
|
||||
|
@ -109,7 +109,10 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
|
||||
};
|
||||
|
||||
GenericBound::TraitBound(
|
||||
PolyTrait { trait_: (trait_ref, &*bindings).clean(cx), generic_params: vec![] },
|
||||
PolyTrait {
|
||||
trait_: (trait_ref, &bindings[..]).clean(cx),
|
||||
generic_params: vec![],
|
||||
},
|
||||
hir::TraitBoundModifier::None,
|
||||
)
|
||||
}
|
||||
@ -761,8 +764,13 @@ fn clean_fn_or_proc_macro(
|
||||
|
||||
impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId) {
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> Function {
|
||||
let (generics, decl) =
|
||||
enter_impl_trait(cx, |cx| (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)));
|
||||
let (generics, decl) = enter_impl_trait(cx, |cx| {
|
||||
// NOTE: generics must be cleaned before args
|
||||
let generics = self.1.clean(cx);
|
||||
let args = (self.0.decl.inputs, self.2).clean(cx);
|
||||
let decl = clean_fn_decl_with_args(cx, self.0.decl, args);
|
||||
(generics, decl)
|
||||
});
|
||||
Function { decl, generics, header: self.0.header }
|
||||
}
|
||||
}
|
||||
@ -804,17 +812,12 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl<'a>, A)
|
||||
where
|
||||
(&'a [hir::Ty<'a>], A): Clean<Arguments>,
|
||||
{
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> FnDecl {
|
||||
FnDecl {
|
||||
inputs: (self.0.inputs, self.1).clean(cx),
|
||||
output: self.0.output.clean(cx),
|
||||
c_variadic: self.0.c_variadic,
|
||||
}
|
||||
}
|
||||
fn clean_fn_decl_with_args(
|
||||
cx: &mut DocContext<'_>,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
args: Arguments,
|
||||
) -> FnDecl {
|
||||
FnDecl { inputs: args, output: decl.output.clean(cx), c_variadic: decl.c_variadic }
|
||||
}
|
||||
|
||||
impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
|
||||
@ -894,7 +897,11 @@ impl Clean<Item> for hir::TraitItem<'_> {
|
||||
}
|
||||
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
|
||||
let (generics, decl) = enter_impl_trait(cx, |cx| {
|
||||
(self.generics.clean(cx), (sig.decl, names).clean(cx))
|
||||
// NOTE: generics must be cleaned before args
|
||||
let generics = self.generics.clean(cx);
|
||||
let args = (sig.decl.inputs, names).clean(cx);
|
||||
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
|
||||
(generics, decl)
|
||||
});
|
||||
let mut t = Function { header: sig.header, decl, generics };
|
||||
if t.header.constness == hir::Constness::Const
|
||||
@ -1727,8 +1734,10 @@ impl Clean<PathSegment> for hir::PathSegment<'_> {
|
||||
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl {
|
||||
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
|
||||
// NOTE: generics must be cleaned before args
|
||||
let generic_params = self.generic_params.iter().map(|x| x.clean(cx)).collect();
|
||||
let decl = (self.decl, self.param_names).clean(cx);
|
||||
let args = (self.decl.inputs, self.param_names).clean(cx);
|
||||
let decl = clean_fn_decl_with_args(cx, self.decl, args);
|
||||
(generic_params, decl)
|
||||
});
|
||||
BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
|
||||
@ -2029,8 +2038,13 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
|
||||
let kind = match item.kind {
|
||||
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
|
||||
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id());
|
||||
let (generics, decl) =
|
||||
enter_impl_trait(cx, |cx| (generics.clean(cx), (decl, names).clean(cx)));
|
||||
let (generics, decl) = enter_impl_trait(cx, |cx| {
|
||||
// NOTE: generics must be cleaned before args
|
||||
let generics = generics.clean(cx);
|
||||
let args = (decl.inputs, names).clean(cx);
|
||||
let decl = clean_fn_decl_with_args(cx, decl, args);
|
||||
(generics, decl)
|
||||
});
|
||||
ForeignFunctionItem(Function {
|
||||
decl,
|
||||
generics,
|
||||
|
Loading…
Reference in New Issue
Block a user