]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/assoc-types.rs
Rollup merge of #56796 - KrishnaSannasi:try_from_impl_change, r=shepmaster
[rust.git] / src / test / rustdoc / assoc-types.rs
1 // ignore-tidy-linelength
2
3 #![crate_type="lib"]
4
5 // @has assoc_types/trait.Index.html
6 pub trait Index<I: ?Sized> {
7     // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
8     // @has - '//code[@id="Output.t"]' 'type Output: ?Sized'
9     type Output: ?Sized;
10     // @has - '//code[@id="index.v"]' 'fn index'
11     // @has - '//*[@id="tymethod.index"]//code' \
12     //      "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
13     // @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \
14     //      "Output"
15     fn index<'a>(&'a self, index: I) -> &'a Self::Output;
16 }
17
18 // @has assoc_types/fn.use_output.html
19 // @has - '//*[@class="rust fn"]' '-> &T::Output'
20 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' 'Output'
21 pub fn use_output<T: Index<usize>>(obj: &T, index: usize) -> &T::Output {
22     obj.index(index)
23 }
24
25 pub trait Feed {
26     type Input;
27 }
28
29 // @has assoc_types/fn.use_input.html
30 // @has - '//*[@class="rust fn"]' 'T::Input'
31 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input'
32 pub fn use_input<T: Feed>(_feed: &T, _element: T::Input) { }
33
34 // @has assoc_types/fn.cmp_input.html
35 // @has - '//*[@class="rust fn"]' 'where T::Input: PartialEq<U::Input>'
36 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input'
37 pub fn cmp_input<T: Feed, U: Feed>(a: &T::Input, b: &U::Input) -> bool
38     where T::Input: PartialEq<U::Input>
39 {
40     a == b
41 }