]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/assoc-type-in-supertrait.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / assoc-type-in-supertrait.rs
1 // run-pass
2 // Test case where an associated type is referenced from within the
3 // supertrait definition. Issue #20220.
4
5
6 use std::vec::IntoIter;
7
8 pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
9     type Key;
10 }
11
12 impl Foo for IntoIter<i32> {
13     type Key = i32;
14 }
15
16 fn sum_foo<F:Foo<Key=i32>>(f: F) -> i32 {
17     f.fold(0, |a,b| a + b)
18 }
19
20 fn main() {
21     let x = sum_foo(vec![11, 10, 1].into_iter());
22     assert_eq!(x, 22);
23 }