1 // Test that we reliably check the value of the associated type.
2
3 #![crate_type = "lib"]
4 #![no_implicit_prelude]
5
6 use std::option::Option::{self, None, Some};
7 use std::vec::Vec;
8
9 trait Iterator {
10 type Item;
11
next(&mut self) -> Option<Self::Item>12 fn next(&mut self) -> Option<Self::Item>;
13 }
14
is_iterator_of<A, I: Iterator<Item=A>>(_: &I)15 fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
16
17 struct Adapter<I> {
18 iter: I,
19 found_none: bool,
20 }
21
22 impl<T, I> Iterator for Adapter<I> where I: Iterator<Item=Option<T>> {
23 type Item = T;
24
next(&mut self) -> Option<T>25 fn next(&mut self) -> Option<T> {
26 loop {}
27 }
28 }
29
test_adapter<T, I: Iterator<Item=Option<T>>>(it: I)30 fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
31 is_iterator_of::<Option<T>, _>(&it); // Sanity check
32 let adapter = Adapter { iter: it, found_none: false };
33 is_iterator_of::<T, _>(&adapter); // OK
34 is_iterator_of::<Option<T>, _>(&adapter); //~ ERROR type mismatch
35 }
36