]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/assoc-types.rs
Merge remote-tracking branch 'upstream/master'
[rust.git] / src / test / rustdoc / assoc-types.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12
13 #![crate_type="lib"]
14
15 // @has assoc_types/trait.Index.html
16 pub trait Index<I: ?Sized> {
17     // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
18     // @has - '//*[@id="Output.t"]//code' 'type Output: ?Sized'
19     type Output: ?Sized;
20     // @has - '//*[@id="index.v"]//code' 'fn index'
21     // @has - '//*[@id="tymethod.index"]//code' \
22     //      "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
23     // @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \
24     //      "Output"
25     fn index<'a>(&'a self, index: I) -> &'a Self::Output;
26 }
27
28 // @has assoc_types/fn.use_output.html
29 // @has - '//*[@class="rust fn"]' '-> &T::Output'
30 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' 'Output'
31 pub fn use_output<T: Index<usize>>(obj: &T, index: usize) -> &T::Output {
32     obj.index(index)
33 }
34
35 pub trait Feed {
36     type Input;
37 }
38
39 // @has assoc_types/fn.use_input.html
40 // @has - '//*[@class="rust fn"]' 'T::Input'
41 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input'
42 pub fn use_input<T: Feed>(_feed: &T, _element: T::Input) { }
43
44 // @has assoc_types/fn.cmp_input.html
45 // @has - '//*[@class="rust fn"]' 'where T::Input: PartialEq<U::Input>'
46 // @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input'
47 pub fn cmp_input<T: Feed, U: Feed>(a: &T::Input, b: &U::Input) -> bool
48     where T::Input: PartialEq<U::Input>
49 {
50     a == b
51 }