-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Flatten and FlatMap have incorrect bounds for their FusedIterator impls #81248
Copy link
Copy link
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I would expect the following code to either not compile (because
itershouldn't implementFusedIterator) or to not panic (because it does, so its contract should guarantee that calling next after the firstNonewill always returnNone), however it compiles and panics:Playground example
This is caused by the fact that the impl of
FusedIteratorforFlattenonly requires the outer iterator to implementFusedIterator, not the inner one, however the implementation doesn't actually fusebackiter, which is what causes the assert to fail. The same problem is present forFlatMap.Possible solutions:
FlattenCompatis implemented to guarantee it to be fused even if the inner iterators are not fused. This would silently change its behavior, however it wouldn't be a breaking change.Additionally I don't think there's anything that requires the outer iterator to always be manually fused in
FlattenCompat. Should we also change it in the process?See also https://users.rust-lang.org/t/why-doesn-t-std-flatten-implement-std-fusediterator-regardless-if-the-outer-or-inner-iterators-do/54477