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