-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Labels
A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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
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
.
devyn, smarnach, roosmaa, marcusklaas, Kestrer and 6 more
Metadata
Metadata
Assignees
Labels
A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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.