Skip to content

Commit 203d400

Browse files
committed
Add rustdoc tests for generic const items
1 parent 55aba32 commit 203d400

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

Diff for: tests/rustdoc/generic-const-items.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(generic_const_items)]
2+
#![allow(incomplete_features)]
3+
4+
// @has 'generic_const_items/constant.K.html'
5+
// @has - '//*[@class="rust item-decl"]//code' \
6+
// "pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> \
7+
// where \
8+
// String: From<T>;"
9+
pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> = None
10+
where
11+
String: From<T>;
12+
13+
// @has generic_const_items/trait.Trait.html
14+
pub trait Trait<T: ?Sized> {
15+
// @has - '//*[@id="associatedconstant.C"]' \
16+
// "const C<'a>: &'a T \
17+
// where \
18+
// T: 'a + Eq"
19+
const C<'a>: &'a T
20+
where
21+
T: 'a + Eq;
22+
}
23+
24+
pub struct Implementor;
25+
26+
// @has generic_const_items/struct.Implementor.html
27+
// @has - '//h3[@class="code-header"]' 'impl Trait<str> for Implementor'
28+
impl Trait<str> for Implementor {
29+
// @has - '//*[@id="associatedconstant.C"]' \
30+
// "const C<'a>: &'a str = \"C\" \
31+
// where \
32+
// str: 'a"
33+
const C<'a>: &'a str = "C"
34+
// In real code we could've left off this bound but adding it explicitly allows us to test if
35+
// we render where-clauses on associated consts inside impl blocks correctly.
36+
where
37+
str: 'a;
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(generic_const_items)]
2+
#![allow(incomplete_features)]
3+
4+
pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> = None
5+
where
6+
String: From<T>;
7+
8+
pub trait Trait<T: ?Sized> {
9+
const C<'a>: &'a T
10+
where
11+
T: 'a + Eq;
12+
}
13+
14+
pub struct Implementor;
15+
16+
impl Trait<str> for Implementor {
17+
const C<'a>: &'a str = "C"
18+
// In real code we could've left off this bound but adding it explicitly allows us to test if
19+
// we render where-clauses on associated consts inside impl blocks correctly.
20+
where
21+
str: 'a;
22+
}

Diff for: tests/rustdoc/inline_cross/generic-const-items.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![crate_name = "user"]
2+
3+
// aux-crate:generic_const_items=generic-const-items.rs
4+
// edition:2021
5+
6+
// @has 'user/constant.K.html'
7+
// @has - '//*[@class="rust item-decl"]//code' \
8+
// "pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> \
9+
// where \
10+
// String: From<T>;"
11+
pub use generic_const_items::K;
12+
13+
// @has user/trait.Trait.html
14+
// @has - '//*[@id="associatedconstant.C"]' \
15+
// "const C<'a>: &'a T \
16+
// where \
17+
// T: 'a + Eq"
18+
pub use generic_const_items::Trait;
19+
20+
// @has user/struct.Implementor.html
21+
// @has - '//h3[@class="code-header"]' 'impl Trait<str> for Implementor'
22+
// @has - '//*[@id="associatedconstant.C"]' \
23+
// "const C<'a>: &'a str = \"C\" \
24+
// where \
25+
// str: 'a"
26+
pub use generic_const_items::Implementor;

0 commit comments

Comments
 (0)