-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Iterator has #[must_use] but ExactSizeIterator does not #102183
Copy link
Copy link
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.
When returning an iterator of an unspecified type, I like to return
impl ExactSizeIteratorwhen I know that the type I'm returning always implements that trait. That gives the caller more options. But I noticed that while the regularIteratortrait has the#[must_use]attribute, theExactSizeIteratortrait does not. This means that the caller isn't warned about ignoring the return value when they call my function. This seems like an odd oversight, so the attribute should probably be added?The same seems to apply to other more specific iterator traits, like
DoubleEndedIteratorandFusedIterator.