diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-11-09 18:23:08 -0800 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-11-09 20:05:42 -0800 |
| commit | cf6a73c1a4a363a1239f2db32b89ff3d2affb6c2 (patch) | |
| tree | 14d47b5406e6f871cc9ab46f46e81f176b7d2e8c | |
| parent | 169b84fee38827d0e4e437696baf7149d9c2adf7 (diff) | |
| download | rust-cf6a73c1a4a363a1239f2db32b89ff3d2affb6c2.tar.gz rust-cf6a73c1a4a363a1239f2db32b89ff3d2affb6c2.zip | |
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.
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2fbccfda8e6..9238a0bc3f3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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, |
