Skip to content

Commit cf6a73c

Browse files
committed
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.
1 parent 169b84f commit cf6a73c

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ fn clean_fn_or_proc_macro(
762762
impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId) {
763763
fn clean(&self, cx: &mut DocContext<'_>) -> Function {
764764
let (generics, decl) = enter_impl_trait(cx, |cx| {
765-
(self.1.clean(cx), clean_fn_decl_with_args(cx, &*self.0.decl, self.2))
765+
let generics = self.1.clean(cx);
766+
let args = (self.0.decl.inputs, self.2).clean(cx);
767+
let decl = clean_fn_decl_with_args(cx, &*self.0.decl, args);
768+
(generics, decl)
766769
});
767770
Function { decl, generics, header: self.0.header }
768771
}
@@ -805,19 +808,12 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
805808
}
806809
}
807810

808-
fn clean_fn_decl_with_args<'a, A: Copy>(
811+
fn clean_fn_decl_with_args(
809812
cx: &mut DocContext<'_>,
810-
decl: &'a hir::FnDecl<'a>,
811-
args: A,
812-
) -> FnDecl
813-
where
814-
(&'a [hir::Ty<'a>], A): Clean<Arguments>,
815-
{
816-
FnDecl {
817-
inputs: (decl.inputs, args).clean(cx),
818-
output: decl.output.clean(cx),
819-
c_variadic: decl.c_variadic,
820-
}
813+
decl: &hir::FnDecl<'_>,
814+
args: Arguments,
815+
) -> FnDecl {
816+
FnDecl { inputs: args, output: decl.output.clean(cx), c_variadic: decl.c_variadic }
821817
}
822818

823819
impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
@@ -897,7 +893,10 @@ impl Clean<Item> for hir::TraitItem<'_> {
897893
}
898894
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
899895
let (generics, decl) = enter_impl_trait(cx, |cx| {
900-
(self.generics.clean(cx), clean_fn_decl_with_args(cx, sig.decl, names))
896+
let generics = self.generics.clean(cx);
897+
let args = (sig.decl.inputs, names).clean(cx);
898+
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
899+
(generics, decl)
901900
});
902901
let mut t = Function { header: sig.header, decl, generics };
903902
if t.header.constness == hir::Constness::Const
@@ -1731,7 +1730,8 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
17311730
fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl {
17321731
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
17331732
let generic_params = self.generic_params.iter().map(|x| x.clean(cx)).collect();
1734-
let decl = clean_fn_decl_with_args(cx, self.decl, self.param_names);
1733+
let args = (self.decl.inputs, self.param_names).clean(cx);
1734+
let decl = clean_fn_decl_with_args(cx, self.decl, args);
17351735
(generic_params, decl)
17361736
});
17371737
BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
@@ -2029,7 +2029,10 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
20292029
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
20302030
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id());
20312031
let (generics, decl) = enter_impl_trait(cx, |cx| {
2032-
(generics.clean(cx), clean_fn_decl_with_args(cx, decl, names))
2032+
let generics = generics.clean(cx);
2033+
let args = (decl.inputs, names).clean(cx);
2034+
let decl = clean_fn_decl_with_args(cx, decl, args);
2035+
(generics, decl)
20332036
});
20342037
ForeignFunctionItem(Function {
20352038
decl,

0 commit comments

Comments
 (0)