Closed
Description
I was playing around with some code which can be found here and is attached below.
When I click on Mir
output I get the following output:
rustc 1.19.0-nightly (d3abc80b3 2017-05-09)
error: no method named `iter` found for type `Iterate<{integer}, [closure@<anon>:30:24: 30:33]>` in the current scope
--> <anon>:32:24
|
32 | println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
| ^^^^
|
= help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `iter`, perhaps you need to implement it:
= help: candidate #1: `core::slice::SliceExt`
error: internal compiler error: /checkout/src/librustc/ty/sty.rs:1316: Ty::fn_sig() called on non-fn type: [type error]
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:428
note: Run with `RUST_BACKTRACE=1` for a backtrace.
I don't have a rust installation locally right now, so I cannot create the backtrace. I'll add it later today.
The code which triggers this:
fn iterate<T, F>(initial: T, f: F) -> Iterate<T, F> {
Iterate {
state: initial,
f: f,
}
}
pub struct Iterate<T, F> {
state: T,
f: F
}
impl<T: Clone, F> Iterator for Iterate<T, F> where F: Fn(&T) -> T {
type Item = T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.state = (self.f)(&self.state);
Some(self.state.clone())
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { (std::usize::MAX, None) }
}
fn main() {
let a = iterate(0, |x| x+1);
println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
}