Skip to content

Vec::drain() doesn't document any guarantees on order #135710

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

Closed
EriKWDev opened this issue Jan 18, 2025 · 1 comment · Fixed by #135728
Closed

Vec::drain() doesn't document any guarantees on order #135710

EriKWDev opened this issue Jan 18, 2025 · 1 comment · Fixed by #135728
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@EriKWDev
Copy link

Location

rustlib/src/rust/library/alloc/src/vec/mod.rs on pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, A>, line 2603 in stable 1.84.0 (9fc6b4312 2025-01-07)

Summary

/// Removes the specified range from the vector in bulk, returning all
/// removed elements as an iterator. If the iterator is dropped before
/// being fully consumed, it drops the remaining removed elements.

"returning all removed elements as an iterator" remains ambiguous on the order of the elements.

I assume drain will continue to yield the items in the range order so could this be a documented guarantee?

@EriKWDev EriKWDev added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jan 18, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 18, 2025
@jieyouxu jieyouxu added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 19, 2025
@hkBst
Copy link
Member

hkBst commented Jan 19, 2025

I was wondering what the documented guarantees for slice iterators were:
"""
Returns an iterator over the slice.

The iterator yields all items from start to end.
"""

so if we document that the iteration is over a slice then we get the ordering guarantees for free.

joboet added a commit to joboet/rust that referenced this issue Jan 24, 2025
document order of items in iterator from drain

fixes rust-lang#135710
@bors bors closed this as completed in 5750815 Jan 25, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#135728 - hkBst:patch-8, r=joboet

document order of items in iterator from drain

fixes rust-lang#135710
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
document order of items in iterator from drain

fixes rust-lang#135710
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants