Closed
Description
(Sorry about the non-informative title, I couldn't come up with a useful description.)
As discovered towards the end of this forum thread, the following code (playground) fails to compile:
trait Trait
where
for<'a> &'a Self::IntoIter: IntoIterator<Item = u32>,
{
type IntoIter;
fn get(&self) -> Self::IntoIter;
}
struct Impl(Vec<u32>);
impl Trait for Impl {
type IntoIter = ImplIntoIter;
fn get(&self) -> Self::IntoIter {
ImplIntoIter(self.0.clone())
}
}
struct ImplIntoIter(Vec<u32>);
impl<'a> IntoIterator for &'a ImplIntoIter {
type Item = <Self::IntoIter as Iterator>::Item;
type IntoIter = std::iter::Cloned<std::slice::Iter<'a, u32>>;
fn into_iter(self) -> Self::IntoIter {
(&self.0).into_iter().cloned()
}
}
I get the following error message:
error[E0271]: type mismatch resolving `for<'a> <std::slice::Iter<'a, u32> as std::iter::Iterator>::Item == &u32`
--> src/lib.rs:13:6
|
13 | impl Trait for Impl {
| ^^^^^ expected bound lifetime parameter 'a, found concrete lifetime
|
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Cloned<std::slice::Iter<'_, u32>>`
Changing the definition of Item
to u32
makes the program compile, but it seems like it should be accepted as it is.