Skip to content

What degree of panic safety is expected for iterator adapters? #58170

Closed

Description

@scottmcm

What state(s) are iterator adapters allowed to be in after a panic, @rust-lang/libs? Obviously they need to memory safe, but how many items are they expected to have consumed? Is it even allowed to call .next() on an (un-fused) iterator after you called, say, .find() on it with a closure that panicked?

Asking because this has just come up in two PRs:

Activity

  1. sfackler commented on Feb 5, 2019

    @sfackler
    Member

    I think I personally see this as an edge case a bit like leaking vec::Drain and the like. We definitely need to avoid allowing memory unsafety, but otherwise I think it's reasonable for the iterator to be in an unspecified state. next could continue to return values, it could return None, etc. In particular, I'd be fine with this behavior changing over time based on how we adjust the iterator's internal implementation.

  2. alexcrichton commented on Feb 5, 2019

    @alexcrichton
    Member

    I personally feel the same way as @sfackler, I don't think we need to hold ourselves to any particular standard in the standard library other then "stay memory safe"

  3. dtolnay commented on Feb 6, 2019

    @dtolnay
    Member

    I agree. I would like for this to be called out briefly in the std::iter module doc, which currently does not mention panic.

  4. added a commit that references this issue on Dec 30, 2019
    97a7b03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions