Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Replace where-bounded Clean impl with simple function #90750

Merged
merged 4 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the commit message, some of these places may not have the ordering requirement, but just to be safe I added comments in almost all of them.

The only place I didn't add a comment is the following

clean/inline.rs
446:            clean::enter_impl_trait(cx, |cx| (tcx.generics_of(did), predicates).clean(cx)),

since it seemed like a different scenario. Let me know if you think I should add a comment there though.

((cx.tcx.generics_of(did), predicates).clean(cx), (did, sig).clean(cx))
});
clean::Function {
Expand Down
50 changes: 32 additions & 18 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down Expand Up @@ -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 }
}
}
Expand Down Expand Up @@ -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>) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -2025,8 +2034,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,
Expand Down