diff options
| author | varkor <github@varkor.com> | 2019-03-13 23:38:33 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-03-18 19:38:23 +0000 |
| commit | 14913159e0509a2b7d1c86984a044b76dd4e4902 (patch) | |
| tree | 2d2f70d84fb44c899c46b51d557407c4e5359f0a /src | |
| parent | c915fe0245c7506e3f15660dee2d597fb48e9230 (diff) | |
| download | rust-14913159e0509a2b7d1c86984a044b76dd4e4902.tar.gz rust-14913159e0509a2b7d1c86984a044b76dd4e4902.zip | |
Implement `Clean` for const generics
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 19 | ||||
| -rw-r--r-- | src/librustdoc/html/format.rs | 6 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5a22614fc71..0f976c11938 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2921,6 +2921,25 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { } } +impl<'tcx> Clean<Constant> for ty::LazyConst<'tcx> { + fn clean(&self, cx: &DocContext<'_>) -> Constant { + if let ty::LazyConst::Evaluated(ct) = self { + ct.clean(cx) + } else { + unimplemented!() // FIXME(const_generics) + } + } +} + +impl<'tcx> Clean<Constant> for ty::Const<'tcx> { + fn clean(&self, cx: &DocContext<'_>) -> Constant { + Constant { + type_: self.ty.clean(cx), + expr: format!("{:?}", self.val), // FIXME(const_generics) + } + } +} + impl Clean<Item> for hir::StructField { fn clean(&self, cx: &DocContext<'_>) -> Item { let local_did = cx.tcx.hir().local_def_id_from_hir_id(self.hir_id); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 36257914d19..2cba3c58889 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -259,6 +259,12 @@ impl fmt::Display for clean::Lifetime { } } +impl fmt::Display for clean::Constant { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}: {}", self.expr, self.type_) + } +} + impl fmt::Display for clean::PolyTrait { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if !self.generic_params.is_empty() { |
