]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-stream.rs
Rollup merge of #76468 - SNCPlay42:lifetime-names, 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 // ignore-compare-mode-chalk
5
6
7 trait Stream {
8     type Car;
9     type Cdr: Stream;
10
11     fn car(&self) -> Self::Car;
12     fn cdr(self) -> Self::Cdr;
13 }
14
15 impl Stream for () {
16     type Car = ();
17     type Cdr = ();
18     fn car(&self) -> () { () }
19     fn cdr(self) -> () { self }
20 }
21
22 impl<T,U> Stream for (T, U)
23     where T : Clone, U : Stream
24 {
25     type Car = T;
26     type Cdr = U;
27     fn car(&self) -> T { self.0.clone() }
28     fn cdr(self) -> U { self.1 }
29 }
30
31 fn main() {
32     let p = (22, (44, (66, ())));
33     assert_eq!(p.car(), 22);
34
35     let p = p.cdr();
36     assert_eq!(p.car(), 44);
37
38     let p = p.cdr();
39     assert_eq!(p.car(), 66);
40 }