Skip to content

Commit 1491315

Browse files
varkoryodaldevoid
andcommitted
Implement Clean for const generics
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent c915fe0 commit 1491315

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustdoc/clean/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,25 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
29212921
}
29222922
}
29232923

2924+
impl<'tcx> Clean<Constant> for ty::LazyConst<'tcx> {
2925+
fn clean(&self, cx: &DocContext<'_>) -> Constant {
2926+
if let ty::LazyConst::Evaluated(ct) = self {
2927+
ct.clean(cx)
2928+
} else {
2929+
unimplemented!() // FIXME(const_generics)
2930+
}
2931+
}
2932+
}
2933+
2934+
impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
2935+
fn clean(&self, cx: &DocContext<'_>) -> Constant {
2936+
Constant {
2937+
type_: self.ty.clean(cx),
2938+
expr: format!("{:?}", self.val), // FIXME(const_generics)
2939+
}
2940+
}
2941+
}
2942+
29242943
impl Clean<Item> for hir::StructField {
29252944
fn clean(&self, cx: &DocContext<'_>) -> Item {
29262945
let local_did = cx.tcx.hir().local_def_id_from_hir_id(self.hir_id);

src/librustdoc/html/format.rs

+6
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ impl fmt::Display for clean::Lifetime {
259259
}
260260
}
261261

262+
impl fmt::Display for clean::Constant {
263+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264+
write!(f, "{}: {}", self.expr, self.type_)
265+
}
266+
}
267+
262268
impl fmt::Display for clean::PolyTrait {
263269
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264270
if !self.generic_params.is_empty() {

0 commit comments

Comments
 (0)