Skip to content

Commit

Permalink
remove 'static bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Feb 20, 2022
1 parent d6307cf commit 55093a1
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 48 deletions.
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
//! Notice that there is a trade-off here. Creating and dropping a `Guard` is not free, since it
//! also needs to interact with said bookkeeping. But if you keep one around for a long time, you
//! may accumulate much garbage which will take up valuable free memory on your system. Use your
//! best judgement in deciding whether or not to re-use a `Guard`. This is also the reason why the
//! map requires that `K: 'static` and `V: 'static`. If we did not, then your keys and values may
//! get dropped far later, potentially after those lifetimes have passed, which would not be sound.
//! best judgement in deciding whether or not to re-use a `Guard`.
//!
//! # Consistency
//!
Expand Down
30 changes: 15 additions & 15 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ where

// ===
// the following methods only see Ks and Vs if there have been inserts.
// modifications to the map are all guarded by thread-safety bounds (Send + Sync + 'static).
// modifications to the map are all guarded by thread-safety bounds (Send + Sync ).
// but _these_ methods do not need to be, since they will never introduce keys or values, only give
// out ones that have already been inserted (which implies they must be thread-safe).
// ===
Expand Down Expand Up @@ -1602,8 +1602,8 @@ where

impl<K, V, S> HashMap<K, V, S>
where
K: 'static + Sync + Send + Clone + Hash + Ord,
V: 'static + Sync + Send,
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
S: BuildHasher,
{
/// Inserts a key-value pair into the map.
Expand Down Expand Up @@ -3007,8 +3007,8 @@ impl<K, V, S> Drop for HashMap<K, V, S> {

impl<K, V, S> Extend<(K, V)> for &HashMap<K, V, S>
where
K: 'static + Sync + Send + Clone + Hash + Ord,
V: 'static + Sync + Send,
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
S: BuildHasher,
{
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
Expand All @@ -3032,8 +3032,8 @@ where

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for &HashMap<K, V, S>
where
K: 'static + Sync + Send + Copy + Hash + Ord,
V: 'static + Sync + Send + Copy,
K: Sync + Send + Copy + Hash + Ord,
V: Sync + Send + Copy,
S: BuildHasher,
{
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T) {
Expand All @@ -3043,8 +3043,8 @@ where

impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
where
K: 'static + Sync + Send + Clone + Hash + Ord,
V: 'static + Sync + Send,
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
S: BuildHasher + Default,
{
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
Expand All @@ -3069,8 +3069,8 @@ where

impl<'a, K, V, S> FromIterator<(&'a K, &'a V)> for HashMap<K, V, S>
where
K: 'static + Sync + Send + Copy + Hash + Ord,
V: 'static + Sync + Send + Copy,
K: Sync + Send + Copy + Hash + Ord,
V: Sync + Send + Copy,
S: BuildHasher + Default,
{
fn from_iter<T: IntoIterator<Item = (&'a K, &'a V)>>(iter: T) -> Self {
Expand All @@ -3080,8 +3080,8 @@ where

impl<'a, K, V, S> FromIterator<&'a (K, V)> for HashMap<K, V, S>
where
K: 'static + Sync + Send + Copy + Hash + Ord,
V: 'static + Sync + Send + Copy,
K: Sync + Send + Copy + Hash + Ord,
V: Sync + Send + Copy,
S: BuildHasher + Default,
{
fn from_iter<T: IntoIterator<Item = &'a (K, V)>>(iter: T) -> Self {
Expand All @@ -3091,8 +3091,8 @@ where

impl<K, V, S> Clone for HashMap<K, V, S>
where
K: 'static + Sync + Send + Clone + Hash + Ord,
V: 'static + Sync + Send + Clone,
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send + Clone,
S: BuildHasher + Clone,
{
fn clone(&self) -> HashMap<K, V, S> {
Expand Down
4 changes: 2 additions & 2 deletions src/map_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ where

impl<K, V, S> HashMapRef<'_, K, V, S>
where
K: 'static + Sync + Send + Clone + Hash + Ord,
V: 'static + Sync + Send,
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
S: BuildHasher,
{
/// Inserts a key-value pair into the map.
Expand Down
24 changes: 12 additions & 12 deletions src/rayon_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::hash::{BuildHasher, Hash};

impl<K, V, S> FromParallelIterator<(K, V)> for HashMap<K, V, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
V: Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
V: Send + Sync,
S: BuildHasher + Default + Sync,
{
fn from_par_iter<I>(par_iter: I) -> Self
Expand All @@ -20,8 +20,8 @@ where

impl<K, V, S> ParallelExtend<(K, V)> for HashMap<K, V, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
V: Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
V: Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand All @@ -34,8 +34,8 @@ where

impl<K, V, S> ParallelExtend<(K, V)> for &HashMap<K, V, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
V: Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
V: Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand All @@ -53,8 +53,8 @@ where

impl<'map, K, V, S> ParallelExtend<(K, V)> for HashMapRef<'map, K, V, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
V: Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
V: Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand All @@ -67,7 +67,7 @@ where

impl<K, S> FromParallelIterator<K> for HashSet<K, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
S: BuildHasher + Default + Sync,
{
fn from_par_iter<I>(par_iter: I) -> Self
Expand All @@ -82,7 +82,7 @@ where

impl<K, S> ParallelExtend<K> for HashSet<K, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand All @@ -95,7 +95,7 @@ where

impl<K, S> ParallelExtend<K> for &HashSet<K, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand All @@ -109,7 +109,7 @@ where

impl<'set, K, S> ParallelExtend<K> for HashSetRef<'set, K, S>
where
K: Clone + Hash + Ord + Send + Sync + 'static,
K: Clone + Hash + Ord + Send + Sync,
S: BuildHasher + Sync,
{
fn par_extend<I>(&mut self, par_iter: I)
Expand Down
12 changes: 6 additions & 6 deletions src/serde_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ where

impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
where
K: 'static + Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
V: 'static + Deserialize<'de> + Send + Sync + Ord,
K: Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
V: Deserialize<'de> + Send + Sync + Ord,
S: Default + BuildHasher,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand All @@ -65,8 +65,8 @@ impl<K, V, S> HashMapVisitor<K, V, S> {

impl<'de, K, V, S> Visitor<'de> for HashMapVisitor<K, V, S>
where
K: 'static + Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
V: 'static + Deserialize<'de> + Send + Sync + Ord,
K: Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
V: Deserialize<'de> + Send + Sync + Ord,
S: Default + BuildHasher,
{
type Value = HashMap<K, V, S>;
Expand Down Expand Up @@ -124,7 +124,7 @@ where

impl<'de, T, S> Deserialize<'de> for HashSet<T, S>
where
T: 'static + Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
T: Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
S: Default + BuildHasher,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand All @@ -151,7 +151,7 @@ impl<T, S> HashSetVisitor<T, S> {

impl<'de, T, S> Visitor<'de> for HashSetVisitor<T, S>
where
T: 'static + Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
T: Deserialize<'de> + Send + Sync + Hash + Clone + Ord,
S: Default + BuildHasher,
{
type Value = HashSet<T, S>;
Expand Down
12 changes: 6 additions & 6 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ where

impl<T, S> HashSet<T, S>
where
T: 'static + Sync + Send + Clone + Hash + Ord,
T: Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
{
/// Adds a value to the set.
Expand Down Expand Up @@ -556,7 +556,7 @@ where

impl<T, S> Extend<T> for &HashSet<T, S>
where
T: 'static + Sync + Send + Clone + Hash + Ord,
T: Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
{
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
Expand All @@ -566,7 +566,7 @@ where

impl<'a, T, S> Extend<&'a T> for &HashSet<T, S>
where
T: 'static + Sync + Send + Copy + Hash + Ord,
T: Sync + Send + Copy + Hash + Ord,
S: BuildHasher,
{
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
Expand All @@ -576,7 +576,7 @@ where

impl<T, S> FromIterator<T> for HashSet<T, S>
where
T: 'static + Sync + Send + Clone + Hash + Ord,
T: Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Default,
{
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Expand All @@ -588,7 +588,7 @@ where

impl<'a, T, S> FromIterator<&'a T> for HashSet<T, S>
where
T: 'static + Sync + Send + Copy + Hash + Ord,
T: Sync + Send + Copy + Hash + Ord,
S: BuildHasher + Default,
{
fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self {
Expand All @@ -600,7 +600,7 @@ where

impl<T, S> Clone for HashSet<T, S>
where
T: 'static + Sync + Send + Clone + Hash + Ord,
T: Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Clone,
{
fn clone(&self) -> HashSet<T, S> {
Expand Down
2 changes: 1 addition & 1 deletion src/set_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where

impl<T, S> HashSetRef<'_, T, S>
where
T: 'static + Sync + Send + Clone + Hash + Ord,
T: Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
{
/// Adds a value to the set.
Expand Down
6 changes: 3 additions & 3 deletions tests/jdk/map_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where

fn t2<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: 'static + Sync + Send + Copy + Hash + Ord + std::fmt::Display,
K: Sync + Send + Copy + Hash + Ord + std::fmt::Display,
{
let mut sum = 0;
let guard = map.guard();
Expand All @@ -49,7 +49,7 @@ where

fn t3<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: 'static + Sync + Send + Copy + Hash + Ord,
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
Expand Down Expand Up @@ -77,7 +77,7 @@ where

fn t5<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: 'static + Sync + Send + Copy + Hash + Ord,
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
Expand Down

0 comments on commit 55093a1

Please sign in to comment.