]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/associated-types-impl-redirect.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / run-pass / associated-types-impl-redirect.rs
CommitLineData
1a4d82fc
JJ
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
5bcae85e 17#![feature(lang_items)]
1a4d82fc
JJ
18#![no_implicit_prelude]
19
20use std::marker::Sized;
21use std::option::Option::{None, Some, self};
22
23trait Iterator {
24 type Item;
25
26 fn next(&mut self) -> Option<Self::Item>;
27}
28
29trait IteratorExt: Iterator + Sized {
30 fn by_ref(&mut self) -> ByRef<Self> {
31 ByRef(self)
32 }
33}
34
35impl<I> IteratorExt for I where I: Iterator {}
36
37struct ByRef<'a, I: 'a + Iterator>(&'a mut I);
38
39impl<'a, I: Iterator> Iterator for ByRef<'a, I> {
40 type Item = I::Item;
41
42 fn next(&mut self) -> Option< <I as Iterator>::Item > {
43 self.0.next()
44 }
45}
46
47fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
48
49fn test<A, I: Iterator<Item=A>>(mut it: I) {
50 is_iterator_of::<A, _>(&it.by_ref());
51}
52
53fn test2<A, I1: Iterator<Item=A>, I2: Iterator<Item=I1::Item>>(mut it: I2) {
54 is_iterator_of::<A, _>(&it)
55}
56
57fn main() { }