|
| 1 | +// Copyright 2015 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 | +// compile-flags: --error-format=human |
| 11 | + |
| 12 | +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 13 | +// file at the top-level directory of this distribution and at |
| 14 | +// http://rust-lang.org/COPYRIGHT. |
| 15 | +// |
| 16 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 17 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 18 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 19 | +// option. This file may not be copied, modified, or distributed |
| 20 | +// except according to those terms. |
| 21 | +// |
| 22 | + |
| 23 | +#![feature(default_type_parameter_fallback)] |
| 24 | + |
| 25 | +use std::vec::IntoIter; |
| 26 | +use std::iter::Sum; |
| 27 | +use std::slice::Iter; |
| 28 | +use std::ops::Add; |
| 29 | + |
| 30 | +trait Itarator: Iterator { |
| 31 | + type Iten; |
| 32 | + // Bug: Even though it's unambiguos, using Self::Iten dosen't work here. |
| 33 | + // probably can be fixed in fn associated_path_def_to_ty. |
| 34 | + fn foo<T:Default=<Self as Itarator>::Iten>(&self) -> T { |
| 35 | + T::default() |
| 36 | + } |
| 37 | + |
| 38 | + fn suma<S=<<Self as Itarator>::Iten as Add>::Output>(self) -> S |
| 39 | + where Self: Sized, |
| 40 | + S: Sum<<Self as Iterator>::Item>, |
| 41 | + { |
| 42 | + Sum::sum(self) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl Itarator for IntoIter<u32> { |
| 47 | + type Iten = <IntoIter<u32> as Iterator>::Item; |
| 48 | +} |
| 49 | + |
| 50 | +impl<'a> Itarator for Iter<'a, u32> { |
| 51 | + type Iten = <Iter<'a, u32> as Iterator>::Item; |
| 52 | +} |
| 53 | + |
| 54 | +fn main() { |
| 55 | + let x = vec![0u32]; |
| 56 | + { |
| 57 | + let v = x.iter(); |
| 58 | + // Bug: if we put a cast such as `as u64`, inference fails. |
| 59 | + //The usual guess is that we propagate the origin but not the default of the inference var. |
| 60 | + v.suma(); |
| 61 | + } |
| 62 | + x.clone().into_iter().suma(); |
| 63 | + x.into_iter().suma(); |
| 64 | +} |
0 commit comments