1 // run-pass 2 // Test a case where the associated type binding (to `bool`, in this 3 // case) is derived from the trait definition. Issue #21636. 4 5 6 use std::vec; 7 8 pub trait BitIter { 9 type Iter: Iterator<Item=bool>; bit_iter(self) -> <Self as BitIter>::Iter10 fn bit_iter(self) -> <Self as BitIter>::Iter; 11 } 12 13 impl BitIter for Vec<bool> { 14 type Iter = vec::IntoIter<bool>; bit_iter(self) -> <Self as BitIter>::Iter15 fn bit_iter(self) -> <Self as BitIter>::Iter { 16 self.into_iter() 17 } 18 } 19 count<T>(arg: T) -> usize where T: BitIter20fn count<T>(arg: T) -> usize 21 where T: BitIter 22 { 23 let mut sum = 0; 24 for i in arg.bit_iter() { 25 if i { 26 sum += 1; 27 } 28 } 29 sum 30 } 31 main()32fn main() { 33 let v = vec![true, false, true]; 34 let c = count(v); 35 assert_eq!(c, 2); 36 } 37