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