-
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
Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant #35354
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I don't understand the issues here enough to review. There's a bunch of new unsafe code though, which is suspicious... cc @rust-lang/libs |
r? @sfackler maybe? |
cc @apasel422 |
@@ -897,8 +898,9 @@ unsafe impl<K: Send, V: Send> Send for IntoIter<K, V> {} | |||
|
|||
/// Iterator over the entries in a table, clearing the table. | |||
pub struct Drain<'a, K: 'a, V: 'a> { | |||
table: &'a mut RawTable<K, V>, | |||
table: Shared<RawTable<K, V>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems curious because today it's implemented in seeming "safe" code, but that didn't get us the right variance by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&mut T
is invariant in T
. But we're reading (K, V)
out of the table, not writing to it, so covariance should be safe. This isn't conveyed by &mut RawTable<K, V>
alone, because the compiler has to assume that such a reference could be written to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah makes sense to me!
@bors: r+ Discussed during triage yesterday, decision was to merge! |
📌 Commit bf592ce has been approved by |
⌛ Testing commit bf592ce with merge 514d4ce... |
Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant Fixed the rest of the Drain iterators.
#30642
Fixed the rest of the Drain iterators.