From 2caeaf54a1d44b1fe95c3ecaee9daa4ac576fd76 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 12 May 2019 16:53:39 +0200 Subject: [PATCH] Fix display of const generics in rustdoc --- src/librustdoc/clean/mod.rs | 5 ++++- src/librustdoc/html/format.rs | 4 +--- src/test/rustdoc/generic-const.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/test/rustdoc/generic-const.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e9ccc61280b10..f91cb469e4629 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3149,7 +3149,10 @@ impl<'tcx> Clean for ty::Const<'tcx> { fn clean(&self, cx: &DocContext<'_>) -> Constant { Constant { type_: self.ty.clean(cx), - expr: format!("{:?}", self.val), // FIXME(const_generics) + expr: match self.val { + ConstValue::Param(ty::ParamConst { name, .. }) => format!("{}", name), + e => format!("{:?}", e), // FIXME generic consts with expressions + }, } } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 3d8af7c7716b1..2784d5b3e10a0 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -262,9 +262,7 @@ impl fmt::Display for clean::Lifetime { impl fmt::Display for clean::Constant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.expr, f)?; - f.write_str(": ")?; - fmt::Display::fmt(&self.type_, f) + fmt::Display::fmt(&self.expr, f) } } diff --git a/src/test/rustdoc/generic-const.rs b/src/test/rustdoc/generic-const.rs new file mode 100644 index 0000000000000..d6794ac8f1d94 --- /dev/null +++ b/src/test/rustdoc/generic-const.rs @@ -0,0 +1,30 @@ +#![feature(const_generics)] +#![crate_name = "foo"] + +// ignore-tidy-linelength + +pub enum Order { + Sorted, + Unsorted, +} + +// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet' +// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl Send for VSet' +// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl Sync for VSet' +pub struct VSet { + inner: Vec, +} + +// @has foo/struct.VSet.html '//h3[@id="impl"]/code' 'impl VSet' +impl VSet { + pub fn new() -> Self { + Self { inner: Vec::new() } + } +} + +// @has foo/struct.VSet.html '//h3[@id="impl-1"]/code' 'impl VSet' +impl VSet { + pub fn new() -> Self { + Self { inner: Vec::new() } + } +}