Skip to content

Commit 0cd06fb

Browse files
remove Clean trait implementation for hir::GenericArgs
1 parent a4f52a5 commit 0cd06fb

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

src/librustdoc/clean/mod.rs

+38-30
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn clean_generic_bound<'tcx>(
123123

124124
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
125125

126-
let generic_args = generic_args.clean(cx);
126+
let generic_args = clean_generic_args(generic_args, cx);
127127
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
128128
else {
129129
bug!("clean: parenthesized `GenericBound::LangItemTrait`");
@@ -1826,39 +1826,44 @@ fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path {
18261826
Path { res: path.res, segments: path.segments.iter().map(|x| x.clean(cx)).collect() }
18271827
}
18281828

1829-
impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
1830-
fn clean(&self, cx: &mut DocContext<'tcx>) -> GenericArgs {
1831-
if self.parenthesized {
1832-
let output = clean_ty(self.bindings[0].ty(), cx);
1833-
let output =
1834-
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
1835-
let inputs = self.inputs().iter().map(|x| clean_ty(x, cx)).collect::<Vec<_>>().into();
1836-
GenericArgs::Parenthesized { inputs, output }
1837-
} else {
1838-
let args = self
1839-
.args
1840-
.iter()
1841-
.map(|arg| match arg {
1842-
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
1843-
GenericArg::Lifetime(clean_lifetime(*lt, cx))
1844-
}
1845-
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
1846-
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
1847-
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
1848-
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
1849-
})
1850-
.collect::<Vec<_>>()
1851-
.into();
1852-
let bindings =
1853-
self.bindings.iter().map(|x| clean_type_binding(x, cx)).collect::<Vec<_>>().into();
1854-
GenericArgs::AngleBracketed { args, bindings }
1855-
}
1829+
fn clean_generic_args<'tcx>(
1830+
generic_args: &hir::GenericArgs<'tcx>,
1831+
cx: &mut DocContext<'tcx>,
1832+
) -> GenericArgs {
1833+
if generic_args.parenthesized {
1834+
let output = clean_ty(generic_args.bindings[0].ty(), cx);
1835+
let output = if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
1836+
let inputs =
1837+
generic_args.inputs().iter().map(|x| clean_ty(x, cx)).collect::<Vec<_>>().into();
1838+
GenericArgs::Parenthesized { inputs, output }
1839+
} else {
1840+
let args = generic_args
1841+
.args
1842+
.iter()
1843+
.map(|arg| match arg {
1844+
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
1845+
GenericArg::Lifetime(clean_lifetime(*lt, cx))
1846+
}
1847+
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
1848+
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
1849+
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
1850+
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
1851+
})
1852+
.collect::<Vec<_>>()
1853+
.into();
1854+
let bindings = generic_args
1855+
.bindings
1856+
.iter()
1857+
.map(|x| clean_type_binding(x, cx))
1858+
.collect::<Vec<_>>()
1859+
.into();
1860+
GenericArgs::AngleBracketed { args, bindings }
18561861
}
18571862
}
18581863

18591864
impl<'tcx> Clean<'tcx, PathSegment> for hir::PathSegment<'tcx> {
18601865
fn clean(&self, cx: &mut DocContext<'tcx>) -> PathSegment {
1861-
PathSegment { name: self.ident.name, args: self.args().clean(cx) }
1866+
PathSegment { name: self.ident.name, args: clean_generic_args(self.args(), cx) }
18621867
}
18631868
}
18641869

@@ -2228,7 +2233,10 @@ fn clean_type_binding<'tcx>(
22282233
cx: &mut DocContext<'tcx>,
22292234
) -> TypeBinding {
22302235
TypeBinding {
2231-
assoc: PathSegment { name: type_binding.ident.name, args: type_binding.gen_args.clean(cx) },
2236+
assoc: PathSegment {
2237+
name: type_binding.ident.name,
2238+
args: clean_generic_args(type_binding.gen_args, cx),
2239+
},
22322240
kind: match type_binding.kind {
22332241
hir::TypeBindingKind::Equality { ref term } => {
22342242
TypeBindingKind::Equality { term: clean_hir_term(term, cx) }

0 commit comments

Comments
 (0)