Implement Clean for const generics

Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
This commit is contained in:
varkor 2019-03-13 23:38:33 +00:00
parent c915fe0245
commit 14913159e0
2 changed files with 25 additions and 0 deletions

View file

@ -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);

View file

@ -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() {