]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-issue-20346.rs
Rollup merge of #52813 - newpavlov:duration_mul_div_extras, r=alexcrichton
[rust.git] / src / test / ui / associated-types / associated-types-issue-20346.rs
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 #![no_implicit_prelude]
15
16 use std::option::Option::{self, None, Some};
17 use std::vec::Vec;
18
19 trait Iterator {
20     type Item;
21
22     fn next(&mut self) -> Option<Self::Item>;
23 }
24
25 fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
26
27 struct Adapter<I> {
28     iter: I,
29     found_none: bool,
30 }
31
32 impl<T, I> Iterator for Adapter<I> where I: Iterator<Item=Option<T>> {
33     type Item = T;
34
35     fn next(&mut self) -> Option<T> {
36         loop {}
37     }
38 }
39
40 fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
41     is_iterator_of::<Option<T>, _>(&it);  // Sanity check
42     let adapter = Adapter { iter: it, found_none: false };
43     is_iterator_of::<T, _>(&adapter); // OK
44     is_iterator_of::<Option<T>, _>(&adapter); //~ ERROR type mismatch
45 }