Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Rua opened this issue Sep 23, 2022 · 1 comment · Fixed by #102287
Closed

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

Rua opened this issue Sep 23, 2022 · 1 comment · Fixed by #102287
Assignees
Labels
A-iterators Area: Iterators C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Rua
Copy link
Contributor

Rua commented Sep 23, 2022

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.

@inquisitivecrystal inquisitivecrystal added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-iterators Area: Iterators C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 23, 2022
@compiler-errors compiler-errors self-assigned this Sep 25, 2022
@compiler-errors
Copy link
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.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 20, 2022
…so-supertrait, r=fee1-dead

Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`

Given `impl Trait`, if one of its supertraits has a `#[must_use]`, then trigger the lint. This means that, for example, `-> impl ExactSizeIterator` also triggers the `must_use` on `trait Iterator`, which fixes rust-lang#102183.

This might need `@rust-lang/lang` sign-off, since it changes the behavior of the lint, so cc'ing them.
@bors bors closed this as completed in 66d91d8 Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-iterators Area: Iterators C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants