Skip to content

Commit e55b020

Browse files
Remove Clean trait implementation for Constant
1 parent 8098f5f commit e55b020

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

src/librustdoc/clean/mod.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,22 @@ impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime {
237237
}
238238
}
239239

240-
impl<'tcx> Clean<'tcx, Constant> for hir::ConstArg {
241-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Constant {
242-
let def_id = cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id();
243-
Constant {
244-
type_: clean_middle_ty(cx.tcx.type_of(def_id), cx, Some(def_id)),
245-
kind: ConstantKind::Anonymous { body: self.value.body },
246-
}
240+
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
241+
let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
242+
Constant {
243+
type_: clean_middle_ty(cx.tcx.type_of(def_id), cx, Some(def_id)),
244+
kind: ConstantKind::Anonymous { body: constant.value.body },
245+
}
246+
}
247+
248+
pub(crate) fn clean_middle_const<'tcx>(
249+
constant: ty::Const<'tcx>,
250+
cx: &mut DocContext<'tcx>,
251+
) -> Constant {
252+
// FIXME: instead of storing the stringified expression, store `self` directly instead.
253+
Constant {
254+
type_: clean_middle_ty(constant.ty(), cx, None),
255+
kind: ConstantKind::TyConst { expr: constant.to_string() },
247256
}
248257
}
249258

@@ -392,7 +401,7 @@ impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> {
392401
fn clean(&self, cx: &mut DocContext<'tcx>) -> Term {
393402
match self {
394403
ty::Term::Ty(ty) => Term::Type(clean_middle_ty(*ty, cx, None)),
395-
ty::Term::Const(c) => Term::Constant(c.clean(cx)),
404+
ty::Term::Const(c) => Term::Constant(clean_middle_const(*c, cx)),
396405
}
397406
}
398407
}
@@ -403,7 +412,7 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
403412
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
404413
hir::Term::Const(c) => {
405414
let def_id = cx.tcx.hir().local_def_id(c.hir_id);
406-
Term::Constant(ty::Const::from_anon_const(cx.tcx, def_id).clean(cx))
415+
Term::Constant(clean_middle_const(ty::Const::from_anon_const(cx.tcx, def_id), cx))
407416
}
408417
}
409418
}
@@ -1468,8 +1477,10 @@ fn maybe_expand_private_type_alias<'tcx>(
14681477
_ => None,
14691478
});
14701479
if let Some(ct) = const_ {
1471-
substs
1472-
.insert(const_param_def_id.to_def_id(), SubstParam::Constant(ct.clean(cx)));
1480+
substs.insert(
1481+
const_param_def_id.to_def_id(),
1482+
SubstParam::Constant(clean_const(ct, cx)),
1483+
);
14731484
}
14741485
// FIXME(const_generics_defaults)
14751486
indices.consts += 1;
@@ -1764,16 +1775,6 @@ pub(crate) fn clean_middle_ty<'tcx>(
17641775
}
17651776
}
17661777

1767-
impl<'tcx> Clean<'tcx, Constant> for ty::Const<'tcx> {
1768-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Constant {
1769-
// FIXME: instead of storing the stringified expression, store `self` directly instead.
1770-
Constant {
1771-
type_: clean_middle_ty(self.ty(), cx, None),
1772-
kind: ConstantKind::TyConst { expr: self.to_string() },
1773-
}
1774-
}
1775-
}
1776-
17771778
pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
17781779
let def_id = cx.tcx.hir().local_def_id(field.hir_id).to_def_id();
17791780
clean_field_with_def_id(def_id, field.ident.name, clean_ty(field.ty, cx), cx)
@@ -1895,7 +1896,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
18951896
}
18961897
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
18971898
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
1898-
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
1899+
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
18991900
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
19001901
})
19011902
.collect::<Vec<_>>()

src/librustdoc/clean/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::render_macro_matchers::render_macro_matcher;
44
use crate::clean::{
5-
clean_middle_ty, inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs,
6-
ImportSource, Item, ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, Type,
7-
TypeBinding, Visibility,
5+
clean_middle_const, clean_middle_ty, inline, Clean, Crate, ExternalCrate, Generic, GenericArg,
6+
GenericArgs, ImportSource, Item, ItemKind, Lifetime, Path, PathSegment, Primitive,
7+
PrimitiveType, Type, TypeBinding, Visibility,
88
};
99
use crate::core::DocContext;
1010
use crate::formats::item_type::ItemType;
@@ -93,7 +93,7 @@ pub(crate) fn substs_to_args<'tcx>(
9393
None
9494
}
9595
GenericArgKind::Type(ty) => Some(GenericArg::Type(clean_middle_ty(ty, cx, None))),
96-
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
96+
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(clean_middle_const(ct, cx)))),
9797
}));
9898
ret_val
9999
}

0 commit comments

Comments
 (0)