Closed
Description
#![feature(conservative_impl_trait)]
struct A {
v: Vec<usize>
}
impl A {
fn foo<'a>(&'a self) -> impl Iterator<Item=usize> + 'a {
(0..self.v.len()).map(move |i| self.v[i])
}
}
fn bar() -> A {
A { v: vec![] }
}
fn baz() -> Vec<usize> {
/* doesn't work:
bar().foo().collect::<Vec<_>>()
*/
/* also doesn't work:
let x = bar();
x.foo().collect::<Vec<_>>()
*/
// you have to do this:
let x = bar();
let x = x.foo();
x.collect::<Vec<_>>()
}
fn main() {}
error: borrowed value does not live long enough
--> <anon>:18:5
|
18 | bar().foo().collect::<Vec<_>>()
| ^^^^^ temporary value created here
...
30 | }
| - temporary value dropped before borrower
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to previous error