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

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

Closed
scottmcm opened this issue Feb 4, 2019 · 3 comments · Fixed by #67564
Closed

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

scottmcm opened this issue Feb 4, 2019 · 3 comments · Fixed by #67564
Labels
A-iterators Area: Iterators T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Feb 4, 2019

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:

@jonas-schievink jonas-schievink added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-iterators Area: Iterators labels Feb 4, 2019
@sfackler
Copy link
Member

sfackler commented Feb 5, 2019

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.

@alexcrichton
Copy link
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"

@dtolnay
Copy link
Member

dtolnay commented Feb 6, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-iterators Area: Iterators 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.

5 participants