]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-types-impl-redirect.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / associated-types-impl-redirect.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 how resolving a projection interacts with inference.  In this
12 // case, we were eagerly unifying the type variable for the iterator
13 // type with `I` from the where clause, ignoring the in-scope `impl`
14 // for `ByRef`. The right answer was to consider the result ambiguous
15 // until more type information was available.
16
17 // ignore-pretty -- FIXME(#17362)
18
19 #![feature(lang_items, unboxed_closures)]
20 #![no_implicit_prelude]
21
22 use std::marker::Sized;
23 use std::option::Option::{None, Some, self};
24
25 trait Iterator {
26     type Item;
27
28     fn next(&mut self) -> Option<Self::Item>;
29 }
30
31 trait IteratorExt: Iterator + Sized {
32     fn by_ref(&mut self) -> ByRef<Self> {
33         ByRef(self)
34     }
35 }
36
37 impl<I> IteratorExt for I where I: Iterator {}
38
39 struct ByRef<'a, I: 'a + Iterator>(&'a mut I);
40
41 impl<'a, I: Iterator> Iterator for ByRef<'a, I> {
42     type Item = I::Item;
43
44     fn next(&mut self) -> Option< <I as Iterator>::Item > {
45         self.0.next()
46     }
47 }
48
49 fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
50
51 fn test<A, I: Iterator<Item=A>>(mut it: I) {
52     is_iterator_of::<A, _>(&it.by_ref());
53 }
54
55 fn test2<A, I1: Iterator<Item=A>, I2: Iterator<Item=I1::Item>>(mut it: I2) {
56     is_iterator_of::<A, _>(&it)
57 }
58
59 fn main() { }