]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-stream.rs
Rollup merge of #62734 - GuillaumeGomez:hide-default-methods, r=Mark-Simulacrum
[rust.git] / src / test / ui / associated-types / associated-types-stream.rs
1 // run-pass
2 // Test references to the trait `Stream` in the bounds for associated
3 // types defined on `Stream`. Issue #20551.
4
5
6 trait Stream {
7     type Car;
8     type Cdr: Stream;
9
10     fn car(&self) -> Self::Car;
11     fn cdr(self) -> Self::Cdr;
12 }
13
14 impl Stream for () {
15     type Car = ();
16     type Cdr = ();
17     fn car(&self) -> () { () }
18     fn cdr(self) -> () { self }
19 }
20
21 impl<T,U> Stream for (T, U)
22     where T : Clone, U : Stream
23 {
24     type Car = T;
25     type Cdr = U;
26     fn car(&self) -> T { self.0.clone() }
27     fn cdr(self) -> U { self.1 }
28 }
29
30 fn main() {
31     let p = (22, (44, (66, ())));
32     assert_eq!(p.car(), 22);
33
34     let p = p.cdr();
35     assert_eq!(p.car(), 44);
36
37     let p = p.cdr();
38     assert_eq!(p.car(), 66);
39 }