-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.