Closed
Description
The error message for this example seems potentially confusing:
#![feature(dyn_trait)]
#![feature(conservative_impl_trait)]
#![feature(underscore_lifetimes)]
fn a<T>(items: &[T]) -> Box<impl Iterator> {
Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
}
fn main() { }
I get:
error[E0621]: explicit lifetime required in the type of `items`
--> src/main.rs:5:29
|
5 | fn a<T>(items: &[T]) -> Box<impl Iterator> {
| ----- ^^^^^^^^^^^^^ lifetime `'static` required
| |
| consider changing the type of `items` to `&'static [T]`
What's going wrong here is that impl Iterator
can only capture lifetimes that it names, and this one doesn't name any lifetimes. It can be fixed by changing to impl Iterator + '_
-- this is probably what we want to suggest? I'm not sure how best to phrase this, suggestions welcome.