Closed
Description
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
compiler-errors commentedon Sep 25, 2022
Probably could also achieve this by triggering
unused_must_use
on anyimpl Trait
whose supertrait has#[must_use]
. Might need lang team sign-off.unused_must_use
onimpl Trait
#102287Rollup merge of rust-lang#102287 - compiler-errors:unused-must-use-al…
Rollup merge of rust-lang#102287 - compiler-errors:unused-must-use-al…