Description
I believe this should successfully compile, but it currently fails claiming that vec's iterator isn't ExactSizeIterator:
fn foo<T>(t: T) -> usize
where
for<'a> &'a T: IntoIterator,
for<'a> <&'a T as IntoIterator>::IntoIter: ExactSizeIterator,
{
t.into_iter().len()
}
fn main() {
foo::<Vec<u32>>(vec![]);
}
error[E0277]: the trait bound `for<'a> <&'a std::vec::Vec<u32> as std::iter::IntoIterator>::IntoIter: std::iter::ExactSizeIterator` is not satisfied
--> src/main.rs:10:5
|
10 | foo::<Vec<u32>>(vec![]);
| ^^^^^^^^^^^^^^^ the trait `for<'a> std::iter::ExactSizeIterator` is not implemented for `<&'a std::vec::Vec<u32> as std::iter::IntoIterator>::IntoIter`
|
= help: the following implementations were found:
<&'a mut I as std::iter::ExactSizeIterator>
note: required by `foo`
--> src/main.rs:1:1
|
1 | / fn foo<T>(t: T) -> usize
2 | | where
3 | | for<'a> &'a T: IntoIterator,
4 | | for<'a> <&'a T as IntoIterator>::IntoIter: ExactSizeIterator,
5 | | {
6 | | t.into_iter().len()
7 | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
Things compile correctly if the bounds are changed to T
rather than for<'a> &'a T
.