Skip to content

Commit 5cdb1e3

Browse files
authored
Rollup merge of #100447 - GuillaumeGomez:rm-clean-impl, r=Dylan-DPC
Remove more Clean trait implementations Follow-up of #99638. r? `@Dylan-DPC`
2 parents 60fa217 + 001cc12 commit 5cdb1e3

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

src/librustdoc/clean/mod.rs

+33-25
Original file line numberDiff line numberDiff line change
@@ -1322,14 +1322,17 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13221322
let trait_def = cx.tcx.associated_item(p.res.def_id()).container_id(cx.tcx);
13231323
let trait_ = self::Path {
13241324
res: Res::Def(DefKind::Trait, trait_def),
1325-
segments: trait_segments.iter().map(|x| x.clean(cx)).collect(),
1325+
segments: trait_segments.iter().map(|x| clean_path_segment(x, cx)).collect(),
13261326
};
13271327
register_res(cx, trait_.res);
13281328
let self_def_id = DefId::local(qself.hir_id.owner.local_def_index);
13291329
let self_type = clean_ty(qself, cx);
13301330
let should_show_cast = compute_should_show_cast(Some(self_def_id), &trait_, &self_type);
13311331
Type::QPath {
1332-
assoc: Box::new(p.segments.last().expect("segments were empty").clean(cx)),
1332+
assoc: Box::new(clean_path_segment(
1333+
p.segments.last().expect("segments were empty"),
1334+
cx,
1335+
)),
13331336
should_show_cast,
13341337
self_type: Box::new(self_type),
13351338
trait_,
@@ -1349,7 +1352,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13491352
let self_type = clean_ty(qself, cx);
13501353
let should_show_cast = compute_should_show_cast(self_def_id, &trait_, &self_type);
13511354
Type::QPath {
1352-
assoc: Box::new(segment.clean(cx)),
1355+
assoc: Box::new(clean_path_segment(segment, cx)),
13531356
should_show_cast,
13541357
self_type: Box::new(self_type),
13551358
trait_,
@@ -1507,7 +1510,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15071510
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
15081511
DynTrait(bounds, lifetime)
15091512
}
1510-
TyKind::BareFn(barefn) => BareFunction(Box::new(barefn.clean(cx))),
1513+
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
15111514
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
15121515
TyKind::Infer | TyKind::Err => Infer,
15131516
TyKind::Typeof(..) => panic!("unimplemented type {:?}", ty.kind),
@@ -1823,7 +1826,10 @@ fn clean_variant_data<'tcx>(
18231826
}
18241827

18251828
fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path {
1826-
Path { res: path.res, segments: path.segments.iter().map(|x| x.clean(cx)).collect() }
1829+
Path {
1830+
res: path.res,
1831+
segments: path.segments.iter().map(|x| clean_path_segment(x, cx)).collect(),
1832+
}
18271833
}
18281834

18291835
fn clean_generic_args<'tcx>(
@@ -1861,28 +1867,30 @@ fn clean_generic_args<'tcx>(
18611867
}
18621868
}
18631869

1864-
impl<'tcx> Clean<'tcx, PathSegment> for hir::PathSegment<'tcx> {
1865-
fn clean(&self, cx: &mut DocContext<'tcx>) -> PathSegment {
1866-
PathSegment { name: self.ident.name, args: clean_generic_args(self.args(), cx) }
1867-
}
1870+
fn clean_path_segment<'tcx>(
1871+
path: &hir::PathSegment<'tcx>,
1872+
cx: &mut DocContext<'tcx>,
1873+
) -> PathSegment {
1874+
PathSegment { name: path.ident.name, args: clean_generic_args(path.args(), cx) }
18681875
}
18691876

1870-
impl<'tcx> Clean<'tcx, BareFunctionDecl> for hir::BareFnTy<'tcx> {
1871-
fn clean(&self, cx: &mut DocContext<'tcx>) -> BareFunctionDecl {
1872-
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
1873-
// NOTE: generics must be cleaned before args
1874-
let generic_params = self
1875-
.generic_params
1876-
.iter()
1877-
.filter(|p| !is_elided_lifetime(p))
1878-
.map(|x| clean_generic_param(cx, None, x))
1879-
.collect();
1880-
let args = clean_args_from_types_and_names(cx, self.decl.inputs, self.param_names);
1881-
let decl = clean_fn_decl_with_args(cx, self.decl, args);
1882-
(generic_params, decl)
1883-
});
1884-
BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
1885-
}
1877+
fn clean_bare_fn_ty<'tcx>(
1878+
bare_fn: &hir::BareFnTy<'tcx>,
1879+
cx: &mut DocContext<'tcx>,
1880+
) -> BareFunctionDecl {
1881+
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
1882+
// NOTE: generics must be cleaned before args
1883+
let generic_params = bare_fn
1884+
.generic_params
1885+
.iter()
1886+
.filter(|p| !is_elided_lifetime(p))
1887+
.map(|x| clean_generic_param(cx, None, x))
1888+
.collect();
1889+
let args = clean_args_from_types_and_names(cx, bare_fn.decl.inputs, bare_fn.param_names);
1890+
let decl = clean_fn_decl_with_args(cx, bare_fn.decl, args);
1891+
(generic_params, decl)
1892+
});
1893+
BareFunctionDecl { unsafety: bare_fn.unsafety, abi: bare_fn.abi, decl, generic_params }
18861894
}
18871895

18881896
fn clean_maybe_renamed_item<'tcx>(

0 commit comments

Comments
 (0)