]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/normalize-assoc-item.rs
Add test, fix pub macro impl, compile error
[rust.git] / src / test / rustdoc / normalize-assoc-item.rs
1 // ignore-tidy-linelength
2 // aux-build:normalize-assoc-item.rs
3 // build-aux-docs
4
5 pub trait Trait {
6     type X;
7 }
8
9 impl Trait for usize {
10     type X = isize;
11 }
12
13 // @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize'
14 pub fn f() -> <usize as Trait>::X {
15     0
16 }
17
18 pub struct S {
19     // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box<S, Global>'
20     pub box_me_up: <S as Trait>::X,
21     // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.generic"]' 'generic: (usize, isize)'
22     pub generic: <Generic<usize> as Trait>::X,
23 }
24
25 impl Trait for S {
26     type X = Box<S>;
27 }
28
29 pub struct Generic<Inner>(Inner);
30
31 impl<Inner: Trait> Trait for Generic<Inner> {
32     type X = (Inner, Inner::X);
33 }
34
35 // These can't be normalized because they depend on a generic parameter.
36 // However the user can choose whether the text should be displayed as `Inner::X` or `<Inner as Trait>::X`.
37
38 // @has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust struct"]' 'pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);'
39 pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);
40
41 // @has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust struct"]' 'pub struct Unknown2<Inner: Trait>(pub Inner::X);'
42 pub struct Unknown2<Inner: Trait>(pub Inner::X);
43
44 trait Lifetimes<'a> {
45     type Y;
46 }
47
48 impl<'a> Lifetimes<'a> for usize {
49     type Y = &'a isize;
50 }
51
52 // @has 'normalize_assoc_item/fn.g.html' '//pre[@class="rust fn"]' "pub fn g() -> &isize"
53 pub fn g() -> <usize as Lifetimes<'static>>::Y {
54     &0
55 }
56
57 // @has 'normalize_assoc_item/constant.A.html' '//pre[@class="rust const"]' "pub const A: &isize"
58 pub const A: <usize as Lifetimes<'static>>::Y = &0;
59
60 // test cross-crate re-exports
61 extern crate inner;
62 // @has 'normalize_assoc_item/fn.foo.html' '//pre[@class="rust fn"]' "pub fn foo() -> i32"
63 pub use inner::foo;
64
65 // @has 'normalize_assoc_item/fn.h.html' '//pre[@class="rust fn"]' "pub fn h<T>() -> IntoIter<T, Global>"
66 pub fn h<T>() -> <Vec<T> as IntoIterator>::IntoIter {
67     vec![].into_iter()
68 }