-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
drain() doc of vector (and others) is still unclear #92765
Comments
Follow-up to my remark and question here: #93769 (comment) I feel like "creates a draining iterator" does more accurately describe the situation. On second thought, and looking at the existing documentation you linked, I do actually agree that those are easier to understand. The tracking issue you link is quite long, so I don't feel like reading through all of it, but I would be interested if you could point out (some of) the concrete comments you're referring to where you witnessed any particular incorrect expectations. Maybe the best solution could be the high-level "Removes the specified range from the vector, returning all removed elements as an iterator"-style documentation in combination with an additional remark later in the documentation that explains why the iterator does nonetheless keep a mutable borrow on the original data-structure for the duration of its existence. So feel free to ignore this point in your PRs if you want, if I come up with a good way of phrasing such an additional remark, I can make a follow-up PR later. |
That seems like a non-issue to me. Conventionally, dropping one thing should never result in leakage of a different thing, unless (that's explicitly documented). To quote myself in a different reply in your PR:
This doesn't mean that I dislike your changes that explicitly call out the dropping, it doesn't hurt to be more explicit, I'm just saying the status quo is less imprecise that you might have assumed. |
It starts even earlier than I thought: e.g. it's mentioned as an argument to let
Good point. |
For my 3rd bullet, I think it's imprecise (I'd use vague) because leaking is listed as one of the normal ways to use the iterator. |
For clarity, I'm not claiming with any authority that My proposed |
Interesting… maybe I should at some point take the time to actually look through that discussion in the tracking issue. There’s a lot of topics being discussed a once though.
Leaking should never be a normal way to use the iterator. The current documentation of Unlike other data types, of course
I fully agree with the observation, and as noted above, I also agree that the wording in terms of "Removes the specified range from the vector, returning all removed elements as an iterator" is easier to understand. I now also agree that this describes the intention of what Of course for a hypothetical |
Not true.
BTreeMap's
That's true for all drain methods without arguments. My proposed |
Ah, okay I see.
Oh, was this “proposed
Well, but e.g. |
The description of Vec::drain:
mem::forget
as if that is just one of the ways to use the iterator, which makes the description harder to understand if you're not advanced in Rust.Vec::drain
grants itself elsewhere, it might be helpful to clarify. None of the otherdrain
methods say this either (Perhaps improve the documentation of drain members further #93769).Vec::into_iter
also doesn't but I believe the fact that the signature says it consumes the container implies it.VecDeque::drain has the same issue (and got missed by #74652). String::drain probably too, it doesn't mention what may happen if you mem::forget the iterator.
@rustbot label A-collections A-docs C-enhancement T-libs-api
The text was updated successfully, but these errors were encountered: