1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_imports)]
4 // Test how resolving a projection interacts with inference.  In this
5 // case, we were eagerly unifying the type variable for the iterator
6 // type with `I` from the where clause, ignoring the in-scope `impl`
7 // for `ByRef`. The right answer was to consider the result ambiguous
8 // until more type information was available.
9 
10 #![feature(lang_items)]
11 #![no_implicit_prelude]
12 
13 use std::marker::Sized;
14 use std::option::Option::{None, Some, self};
15 
16 trait Iterator {
17     type Item;
18 
next(&mut self) -> Option<Self::Item>19     fn next(&mut self) -> Option<Self::Item>;
20 }
21 
22 trait IteratorExt: Iterator + Sized {
by_ref(&mut self) -> ByRef<Self>23     fn by_ref(&mut self) -> ByRef<Self> {
24         ByRef(self)
25     }
26 }
27 
28 impl<I> IteratorExt for I where I: Iterator {}
29 
30 struct ByRef<'a, I: 'a + Iterator>(&'a mut I);
31 
32 impl<'a, A, I> Iterator for ByRef<'a, I> where I: Iterator<Item=A> {
33     type Item = A;
34 
next(&mut self) -> Option< <I as Iterator>::Item >35     fn next(&mut self) -> Option< <I as Iterator>::Item > {
36         self.0.next()
37     }
38 }
39 
is_iterator_of<A, I: Iterator<Item=A>>(_: &I)40 fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
41 
test<A, I: Iterator<Item=A>>(mut it: I)42 fn test<A, I: Iterator<Item=A>>(mut it: I) {
43     is_iterator_of::<A, _>(&it.by_ref());
44 }
45 
main()46 fn main() { }
47