]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-41880.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / issues / issue-41880.rs
1 // Copyright 2017 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 fn iterate<T, F>(initial: T, f: F) -> Iterate<T, F> {
12     Iterate {
13         state: initial,
14         f: f,
15     }
16 }
17
18 pub struct Iterate<T, F> {
19     state: T,
20     f: F
21 }
22
23 impl<T: Clone, F> Iterator for Iterate<T, F> where F: Fn(&T) -> T {
24     type Item = T;
25
26     #[inline]
27     fn next(&mut self) -> Option<Self::Item> {
28         self.state = (self.f)(&self.state);
29         Some(self.state.clone())
30     }
31     #[inline]
32     fn size_hint(&self) -> (usize, Option<usize>) { (std::usize::MAX, None) }
33 }
34
35 fn main() {
36     let a = iterate(0, |x| x+1);
37     println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
38     //~^ ERROR no method named `iter` found for type `Iterate<{integer}
39 }