|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// Test that we reliably check the value of the associated type. |
| 12 | + |
| 13 | +#![crate_type = "lib"] |
| 14 | +#![feature(associated_types)] |
| 15 | +#![no_implicit_prelude] |
| 16 | + |
| 17 | +use std::option::Option::{None, Some, mod}; |
| 18 | +use std::vec::Vec; |
| 19 | + |
| 20 | +trait Iterator { |
| 21 | + type Item; |
| 22 | + |
| 23 | + fn next(&mut self) -> Option<Self::Item>; |
| 24 | +} |
| 25 | + |
| 26 | +fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {} |
| 27 | + |
| 28 | +struct Adapter<I> { |
| 29 | + iter: I, |
| 30 | + found_none: bool, |
| 31 | +} |
| 32 | + |
| 33 | +impl<T, I> Iterator for Adapter<I> where I: Iterator<Item=Option<T>> { |
| 34 | + type Item = T; |
| 35 | + |
| 36 | + fn next(&mut self) -> Option<T> { |
| 37 | + loop {} |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) { |
| 42 | + is_iterator_of::<Option<T>, _>(&it); // Sanity check |
| 43 | + let adapter = Adapter { iter: it, found_none: false }; |
| 44 | + is_iterator_of::<T, _>(&adapter); // OK |
| 45 | + is_iterator_of::<Option<T>, _>(&adapter); //~ ERROR type mismatch |
| 46 | +} |
0 commit comments