-
Notifications
You must be signed in to change notification settings - Fork 48
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
Relax bounds on many methods to be minimal #64
Conversation
Sorry for all the code motion — this also groups together methods that have the same bounds. |
Codecov Report
|
This patch removes a large number of unnecessary bounds. Beyond the obvious ones (like iterators do not require `Hash` and constructors do not need `BuildHasher`), the biggest change is that the thread-safety bounds are now _only_ placed on methods that modify the map. The reasoning here is simple enough: if the threads-safety bounds do not hold for K/V, then the map must be empty, and if the map is empty, the read operations are fine even if the K/V type is not thread-safe.
What a confusing diff... apart from the review comment I am curious about This is definitely also correct if we initialize from |
@domenicquirl yeah, I had the same though going through it. As to whether it makes sense to special-case, I'm genuinely not sure. Maybe? My inclination would be to land this first though, and then add a specialized variant of |
I think I dislike this enough logically that I am in favour of adding a special case for it. Especially since most of what this change does is allowing for "unused" maps to be constructed without any constraints, in the sense that if one wants to handle entries, then the full trait bounds apply anyways (not that I would have a concrete use case for this). In my opinion it's worth the extra implementation, only we should take care to document this well and make it clear why there are two As for whether to add this now or in a later PR, I don't really care. I will probably touch a few of the trait bounds again anyways for everything that requires |
This patch removes a large number of unnecessary bounds. Beyond the
obvious ones (like iterators do not require
Hash
and constructors donot need
BuildHasher
), the biggest change is that the thread-safetybounds are now only placed on methods that modify the map. The
reasoning here is simple enough: if the threads-safety bounds do not
hold for K/V, then the map must be empty, and if the map is empty, the
read operations are fine even if the K/V type is not thread-safe.
Inspired by rust-lang/rust#67642
This change is