-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
estebank, kornelski and ah-
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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.