Skip to content

Iterator has #[must_use] but ExactSizeIterator does not #102183

Closed
@Rua

Description

@Rua
Contributor

When returning an iterator of an unspecified type, I like to return impl ExactSizeIterator when I know that the type I'm returning always implements that trait. That gives the caller more options. But I noticed that while the regular Iterator trait has the #[must_use] attribute, the ExactSizeIterator trait 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 DoubleEndedIterator and FusedIterator.

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Sep 23, 2022
compiler-errors

compiler-errors commented on Sep 25, 2022

@compiler-errors
Member

Probably could also achieve this by triggering unused_must_use on any impl Trait whose supertrait has #[must_use]. Might need lang team sign-off.

added a commit that references this issue on Oct 20, 2022

Rollup merge of rust-lang#102287 - compiler-errors:unused-must-use-al…

8fcf2f7
added a commit that references this issue on Oct 21, 2022

Rollup merge of rust-lang#102287 - compiler-errors:unused-must-use-al…

66d91d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-iteratorsArea: IteratorsC-enhancementCategory: 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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @Rua@compiler-errors@inquisitivecrystal

    Issue actions

      `Iterator` has `#[must_use]` but `ExactSizeIterator` does not · Issue #102183 · rust-lang/rust