Skip to content

Commit e0d2f74

Browse files
committed
Auto merge of #60760 - GuillaumeGomez:generic-display, r=varkor,badboy
Fix display of const generics in rustdoc <img width="745" alt="Screenshot 2019-05-18 at 15 45 22" src="https://user-images.githubusercontent.com/3050060/57970638-04854e80-7984-11e9-9f04-da6b51ec8bc7.png"> Part of #60737. cc @varkor r? @badboy
2 parents 26ab324 + 2caeaf5 commit e0d2f74

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/librustdoc/clean/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,10 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
31493149
fn clean(&self, cx: &DocContext<'_>) -> Constant {
31503150
Constant {
31513151
type_: self.ty.clean(cx),
3152-
expr: format!("{:?}", self.val), // FIXME(const_generics)
3152+
expr: match self.val {
3153+
ConstValue::Param(ty::ParamConst { name, .. }) => format!("{}", name),
3154+
e => format!("{:?}", e), // FIXME generic consts with expressions
3155+
},
31533156
}
31543157
}
31553158
}

src/librustdoc/html/format.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ impl fmt::Display for clean::Lifetime {
262262

263263
impl fmt::Display for clean::Constant {
264264
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
265-
fmt::Display::fmt(&self.expr, f)?;
266-
f.write_str(": ")?;
267-
fmt::Display::fmt(&self.type_, f)
265+
fmt::Display::fmt(&self.expr, f)
268266
}
269267
}
270268

src/test/rustdoc/generic-const.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(const_generics)]
2+
#![crate_name = "foo"]
3+
4+
// ignore-tidy-linelength
5+
6+
pub enum Order {
7+
Sorted,
8+
Unsorted,
9+
}
10+
11+
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
12+
// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl<const ORDER: Order, T> Send for VSet<T, ORDER>'
13+
// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl<const ORDER: Order, T> Sync for VSet<T, ORDER>'
14+
pub struct VSet<T, const ORDER: Order> {
15+
inner: Vec<T>,
16+
}
17+
18+
// @has foo/struct.VSet.html '//h3[@id="impl"]/code' 'impl<T> VSet<T, { Order::Sorted }>'
19+
impl <T> VSet<T, {Order::Sorted}> {
20+
pub fn new() -> Self {
21+
Self { inner: Vec::new() }
22+
}
23+
}
24+
25+
// @has foo/struct.VSet.html '//h3[@id="impl-1"]/code' 'impl<T> VSet<T, { Order::Unsorted }>'
26+
impl <T> VSet<T, {Order::Unsorted}> {
27+
pub fn new() -> Self {
28+
Self { inner: Vec::new() }
29+
}
30+
}

0 commit comments

Comments
 (0)