about summary refs log tree commit diff
path: root/tests/ui/traits/assoc-type-in-supertrait.rs
blob: 8ea1f1709533ee65c3f99db4ff4aeecb8e25fa62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//@ run-pass
// Test case where an associated type is referenced from within the
// supertrait definition. Issue #20220.


use std::vec::IntoIter;

pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
    type Key;
}

impl Foo for IntoIter<i32> {
    type Key = i32;
}

fn sum_foo<F:Foo<Key=i32>>(f: F) -> i32 {
    f.fold(0, |a,b| a + b)
}

fn main() {
    let x = sum_foo(vec![11, 10, 1].into_iter());
    assert_eq!(x, 22);
}