]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-stream.rs
Merge commit '4f3ab69ea0a0908260944443c739426cc384ae1a' into clippyup
[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 trait Stream {
6     type Car;
7     type Cdr: Stream;
8
9     fn car(&self) -> Self::Car;
10     fn cdr(self) -> Self::Cdr;
11 }
12
13 impl Stream for () {
14     type Car = ();
15     type Cdr = ();
16     fn car(&self) -> () { () }
17     fn cdr(self) -> () { self }
18 }
19
20 impl<T,U> Stream for (T, U)
21     where T : Clone, U : Stream
22 {
23     type Car = T;
24     type Cdr = U;
25     fn car(&self) -> T { self.0.clone() }
26     fn cdr(self) -> U { self.1 }
27 }
28
29 fn main() {
30     let p = (22, (44, (66, ())));
31     assert_eq!(p.car(), 22);
32
33     let p = p.cdr();
34     assert_eq!(p.car(), 44);
35
36     let p = p.cdr();
37     assert_eq!(p.car(), 66);
38 }