]> git.proxmox.com Git - rustc.git/blob - tests/ui/issues/issue-22036.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / issues / issue-22036.rs
1 // run-pass
2
3 trait DigitCollection: Sized {
4 type Iter: Iterator<Item = u8>;
5 fn digit_iter(self) -> Self::Iter;
6
7 fn digit_sum(self) -> u32 {
8 self.digit_iter()
9 .map(|digit: u8| digit as u32)
10 .fold(0, |sum, digit| sum + digit)
11 }
12 }
13
14 impl<I> DigitCollection for I where I: Iterator<Item=u8> {
15 type Iter = I;
16
17 fn digit_iter(self) -> I {
18 self
19 }
20 }
21
22 fn main() {
23 let xs = vec![1, 2, 3, 4, 5];
24 assert_eq!(xs.into_iter().digit_sum(), 15);
25 }