Associated type and where clause errors


#1

When compiling the following:

trait Collection: IntoIterator
    where for<'a> &'a Self: IntoIterator<Item=&'a <Self as IntoIterator>::Item>,
          for<'a> &'a mut Self: IntoIterator<Item=&'a mut <Self as IntoIterator>::Item>,
{
    fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
        self.into_iter()
    }
}

impl<T> Collection for Vec<T> { }

fn test<C: Collection<Item=u8>>(c: &C) {
    let iter: <&C as IntoIterator>::IntoIter = c.iter();
}

fn main() {
    test(&vec![1, 2, 3]);
}

I’m getting the following errors:

test.rs:13:15: 13:45 error: the trait `core::iter::Iterator` is not implemented for the type `&C` [E0277]
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:13:15: 13:45 note: `&C` is not an iterator; maybe try calling `.iter()` or a similar method
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:13:50: 13:56 error: the trait `core::iter::Iterator` is not implemented for the type `&C` [E0277]
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
test.rs:13:50: 13:56 note: `&C` is not an iterator; maybe try calling `.iter()` or a similar method
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
test.rs:13:50: 13:56 error: the trait `for<'a> core::iter::Iterator` is not implemented for the type `&'a C` [E0277]
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
test.rs:13:50: 13:56 note: `&'a C` is not an iterator; maybe try calling `.iter()` or a similar method
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
test.rs:13:50: 13:56 error: the trait `core::iter::Iterator` is not implemented for the type `C` [E0277]
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
test.rs:13:50: 13:56 note: `C` is not an iterator; maybe try calling `.iter()` or a similar method
test.rs:13     let iter: <&C as IntoIterator>::IntoIter = c.iter();
                                                            ^~~~~~
error: aborting due to 4 previous errors

Does anyone know what I’m doing wrong?


#2

Type errors seem to be related to: https://github.com/rust-lang/rust/issues/26026