]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/normalize-assoc-item.rs
Rollup merge of #93755 - ChayimFriedman2:allow-comparing-vecs-with-different-allocato...
[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 // 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 // @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize'
15 pub fn f() -> <usize as Trait>::X {
16     0
17 }
18
19 pub struct S {
20     // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box<S, Global>'
21     pub box_me_up: <S as Trait>::X,
22     // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.generic"]' 'generic: (usize, isize)'
23     pub generic: <Generic<usize> as Trait>::X,
24 }
25
26 impl Trait for S {
27     type X = Box<S>;
28 }
29
30 pub struct Generic<Inner>(Inner);
31
32 impl<Inner: Trait> Trait for Generic<Inner> {
33     type X = (Inner, Inner::X);
34 }
35
36 // These can't be normalized because they depend on a generic parameter.
37 // However the user can choose whether the text should be displayed as `Inner::X` or `<Inner as Trait>::X`.
38
39 // @has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust struct"]' 'pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);'
40 pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);
41
42 // @has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust struct"]' 'pub struct Unknown2<Inner: Trait>(pub Inner::X);'
43 pub struct Unknown2<Inner: Trait>(pub Inner::X);
44
45 trait Lifetimes<'a> {
46     type Y;
47 }
48
49 impl<'a> Lifetimes<'a> for usize {
50     type Y = &'a isize;
51 }
52
53 // @has 'normalize_assoc_item/fn.g.html' '//pre[@class="rust fn"]' "pub fn g() -> &isize"
54 pub fn g() -> <usize as Lifetimes<'static>>::Y {
55     &0
56 }
57
58 // @has 'normalize_assoc_item/constant.A.html' '//pre[@class="rust const"]' "pub const A: &isize"
59 pub const A: <usize as Lifetimes<'static>>::Y = &0;
60
61 // test cross-crate re-exports
62 extern crate inner;
63 // @has 'normalize_assoc_item/fn.foo.html' '//pre[@class="rust fn"]' "pub fn foo() -> i32"
64 pub use inner::foo;
65
66 // @has 'normalize_assoc_item/fn.h.html' '//pre[@class="rust fn"]' "pub fn h<T>() -> IntoIter<T, Global>"
67 pub fn h<T>() -> <Vec<T> as IntoIterator>::IntoIter {
68     vec![].into_iter()
69 }