Skip to content

Add a safety warning in ExactSizeIterator documentation #81739

Closed
@Qwaz

Description

@Qwaz

ExactSizeIterator is a safe trait. Thus, unsafe code cannot rely on the correctness of size_hint() when it is related to the program safety. However, this trait seems to be used in the wild in such context, for example:
https://github.com/tiby312/reorder/blob/59ad9be6989de8eee948510b850851105ecad22e/src/lib.rs#L44-L57

I believe adding a warning about such misunderstanding like what is written in the read() document help prevent the future soundness bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-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

    No branches or pull requests

    Issue actions