-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow binary HashSet operations to be generic over hashers #48363
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
Allow binary HashSet operations to be generic over hashers #48363
Conversation
Allow the two sets that are parameters in `HashSet::{difference, intersection, is_disjoint, is_subset, is_superset}` to have different hashing algorithms. Fixes rust-lang#31712.
r? @bluss (rust_highfive has picked a reviewer for you, use r? to override) |
@bluss ping from triage! Can you (or someone else from @rust-lang/libs) review this PR? |
Thanks for the PR @varkor! This looks like a great idea to me. Technically this is a breaking change due to the addition of a type parameter on the method (I think?) but I'm having trouble coming up with a realistic case where it'd actually cause breakage. In that sense I think we should be good to go to merge this, but let's check with... @rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
src/libstd/collections/hash/set.rs
Outdated
@@ -337,7 +337,7 @@ impl<T, S> HashSet<T, S> | |||
/// assert_eq!(diff, [4].iter().collect()); | |||
/// ``` | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> { | |||
pub fn difference<'a, U>(&'a self, other: &'a HashSet<T, U>) -> Difference<'a, T, U> { |
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.
Should we uniformly require the BuildHasher bound here? Not sure if it would matter but it might be safer to add?
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.
Yeah, I find it hard to reason about inference issues in cases like this. I agree that it probably is a good idea to make explicit.
Ping from the release team! @sfackler and @withoutboats, there are some nice checkboxes waiting for you :) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Seems plausible to cause inference breakage, maybe we should do a crater run. |
@rust-lang/infra, mind doing a crater run for this? |
@bors try |
…<try> Allow binary HashSet operations to be generic over hashers Allow the two sets that are parameters in `HashSet::{difference, intersection, is_disjoint, is_subset, is_superset}` to have different hashing algorithms. Fixes #31712.
☀️ Test successful - status-travis |
Added to the crater queue. |
The final comment period is now complete. |
Crater run started |
Hi @alexcrichton (crater requester/PR reviewer)! Crater results are at: http://cargobomb-reports.s3.amazonaws.com/pr-48363/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. If you see any spurious failures not on the list, please make a PR against that file. (interested observers: Crater is a tool for testing the impact of changes on the crates.io ecosystem. You can find out more at the repo if you're curious) |
Some legit inference failures (only checked the last few): pombase.pombase-chado-json.83d98003936c84b11f6eb9421bbe0e652f56c684
marte.baraha.2f0407c1eeaa5973b3e9b207b55b34d8988f34aa
voidmap-1.1.2
|
Alas! Looks like we won't be able to land this :( |
I believe this is a "making an already generic parameter more generic" case that could be possible with type parameter fallback. |
@leodasvacas: yes, this is precisely what I was thinking. This PR is something to revisit once we have something like that in place. |
Allow the two sets that are parameters in
HashSet::{difference, intersection, is_disjoint, is_subset, is_superset}
to have different hashing algorithms. Fixes #31712.