Skip to content

Commit

Permalink
Rollup merge of rust-lang#61293 - varkor:rustdoc-print-const-generic,…
Browse files Browse the repository at this point in the history
… r=GuillaumeGomez

Print const generics properly in rustdoc

Now that rust-lang#59276 is merged, we can print consts properly in rustdoc.

Fixes rust-lang#60737.
Fixes rust-lang#61257.

r? @GuillaumeGomez
  • Loading branch information
oli-obk committed May 29, 2019
2 parents 20f462d + 9c9b7b4 commit 9cc289e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3145,10 +3145,7 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
fn clean(&self, cx: &DocContext<'_>) -> Constant {
Constant {
type_: self.ty.clean(cx),
expr: match self.val {
ConstValue::Param(ty::ParamConst { name, .. }) => format!("{}", name),
e => format!("{:?}", e), // FIXME generic consts with expressions
},
expr: format!("{}", self),
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc/const-generics/add-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ignore-tidy-linelength

#![feature(const_generics)]

#![crate_name = "foo"]

use std::ops::Add;

// @has foo/struct.Simd.html '//pre[@class="rust struct"]' 'pub struct Simd<T, const WIDTH: usize>'
pub struct Simd<T, const WIDTH: usize> {
inner: T,
}

// @has foo/struct.Simd.html '//div[@id="implementations-list"]/h3/code' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
impl Add for Simd<u8, 16> {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self { inner: 0 }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// ignore-tidy-linelength

#![feature(const_generics)]
#![crate_name = "foo"]

// ignore-tidy-linelength
#![crate_name = "foo"]

pub enum Order {
Sorted,
Expand Down

0 comments on commit 9cc289e

Please sign in to comment.