Remove where bound from clean_fn_decl_with_args
Basically, this entails moving the arguments cleaning to the call site.
I extracted several local variables because:
1. It makes the code easier to read and understand.
2. If I hadn't, the extra `clean()` calls would have caused complicated
tuples to be split across several lines.
3. I couldn't just extract local variables for `args` because then the
arguments would be cleaned *before* the generics, while rustdoc expects
them to be cleaned *after*. Only extracting `args` caused panics like
this:
thread 'rustc' panicked at 'assertion failed: cx.impl_trait_bounds.is_empty()',
src/librustdoc/clean/utils.rs:462:5
Extracting variables makes the control flow -- and the required
order of cleaning -- more explicit.
This commit is contained in:
parent
169b84fee3
commit
cf6a73c1a4
1 changed files with 19 additions and 16 deletions
|
|
@ -762,7 +762,10 @@ 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), clean_fn_decl_with_args(cx, &*self.0.decl, self.2))
|
||||
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 }
|
||||
}
|
||||
|
|
@ -805,19 +808,12 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
|
|||
}
|
||||
}
|
||||
|
||||
fn clean_fn_decl_with_args<'a, A: Copy>(
|
||||
fn clean_fn_decl_with_args(
|
||||
cx: &mut DocContext<'_>,
|
||||
decl: &'a hir::FnDecl<'a>,
|
||||
args: A,
|
||||
) -> FnDecl
|
||||
where
|
||||
(&'a [hir::Ty<'a>], A): Clean<Arguments>,
|
||||
{
|
||||
FnDecl {
|
||||
inputs: (decl.inputs, args).clean(cx),
|
||||
output: decl.output.clean(cx),
|
||||
c_variadic: decl.c_variadic,
|
||||
}
|
||||
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>) {
|
||||
|
|
@ -897,7 +893,10 @@ 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), clean_fn_decl_with_args(cx, sig.decl, names))
|
||||
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
|
||||
|
|
@ -1731,7 +1730,8 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
|||
fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl {
|
||||
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
|
||||
let generic_params = self.generic_params.iter().map(|x| x.clean(cx)).collect();
|
||||
let decl = clean_fn_decl_with_args(cx, self.decl, self.param_names);
|
||||
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,7 +2029,10 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
|
|||
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), clean_fn_decl_with_args(cx, decl, names))
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue