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