Skip to content

Commit 9cc289e

Browse files
authored
Rollup merge of rust-lang#61293 - varkor:rustdoc-print-const-generic, 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
2 parents 20f462d + 9c9b7b4 commit 9cc289e

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/librustdoc/clean/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3145,10 +3145,7 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
31453145
fn clean(&self, cx: &DocContext<'_>) -> Constant {
31463146
Constant {
31473147
type_: self.ty.clean(cx),
3148-
expr: match self.val {
3149-
ConstValue::Param(ty::ParamConst { name, .. }) => format!("{}", name),
3150-
e => format!("{:?}", e), // FIXME generic consts with expressions
3151-
},
3148+
expr: format!("{}", self),
31523149
}
31533150
}
31543151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ignore-tidy-linelength
2+
3+
#![feature(const_generics)]
4+
5+
#![crate_name = "foo"]
6+
7+
use std::ops::Add;
8+
9+
// @has foo/struct.Simd.html '//pre[@class="rust struct"]' 'pub struct Simd<T, const WIDTH: usize>'
10+
pub struct Simd<T, const WIDTH: usize> {
11+
inner: T,
12+
}
13+
14+
// @has foo/struct.Simd.html '//div[@id="implementations-list"]/h3/code' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
15+
impl Add for Simd<u8, 16> {
16+
type Output = Self;
17+
18+
fn add(self, rhs: Self) -> Self::Output {
19+
Self { inner: 0 }
20+
}
21+
}

src/test/rustdoc/generic-const.rs src/test/rustdoc/const-generics/const-impl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// ignore-tidy-linelength
2+
13
#![feature(const_generics)]
2-
#![crate_name = "foo"]
34

4-
// ignore-tidy-linelength
5+
#![crate_name = "foo"]
56

67
pub enum Order {
78
Sorted,

0 commit comments

Comments
 (0)