Closed
Description
struct A {
x: [(u32, u32); 10]
}
impl A {
fn iter_values(&self) -> impl Iterator<Item=u32>{
self.x.iter().map(|a| a.0)
}
}
error[E0564]: only named lifetimes are allowed in `impl Trait`, but `` was found in the type `std::iter::Map<std::slice::Iter<'_, (u32, u32)>, [closure@src/main.rs:12:27: 12:34]>`
--> src/main.rs:11:30
|
11 | fn iter_values(&self) -> impl Iterator<Item=u32>{
| ^^^^^^^^^^^^^^^^^^^^^^^
The correct fix is fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a
(or use into_iter
, but that's not always an option), however this error message has no indication that this is the way to go in, in fact not many people are aware of the Trait + 'a
syntax. We probably can do better.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Category: An issue proposing an enhancement or a PR with one.Relevant to the compiler team, which will review and decide on the PR/issue.Working group: Diagnostics