From 03c53df88b89eaa843ee09f3b3584e32b4f00140 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 9 Aug 2023 20:02:22 -0700 Subject: [PATCH] fix: set in_use to true while cloning --- src/index_map.rs | 10 +++++++--- src/index_set.rs | 10 +++++++--- src/map.rs | 20 ++++++++++++++------ src/vec.rs | 1 - 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/index_map.rs b/src/index_map.rs index 50d021f..b96179f 100644 --- a/src/index_map.rs +++ b/src/index_map.rs @@ -238,9 +238,13 @@ impl Default for FrozenIndexMap { impl Clone for FrozenIndexMap { fn clone(&self) -> Self { - Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), - in_use: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } diff --git a/src/index_set.rs b/src/index_set.rs index 28819d0..59588ad 100644 --- a/src/index_set.rs +++ b/src/index_set.rs @@ -183,9 +183,13 @@ impl Default for FrozenIndexSet { impl Clone for FrozenIndexSet { fn clone(&self) -> Self { - Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { set: unsafe { self.set.get().as_ref().unwrap() }.clone().into(), - in_use: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } diff --git a/src/map.rs b/src/map.rs index e8cf7c1..1c94868 100644 --- a/src/map.rs +++ b/src/map.rs @@ -272,10 +272,14 @@ impl Default for FrozenMap { impl Clone for FrozenMap { fn clone(&self) -> Self { - Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), - in_use: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } @@ -507,9 +511,13 @@ impl Default for FrozenBTreeMap { impl Clone for FrozenBTreeMap { fn clone(&self) -> Self { - Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), - in_use: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } diff --git a/src/vec.rs b/src/vec.rs index 891a89c..592e443 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -224,7 +224,6 @@ impl Clone for FrozenVec { } } - impl From> for FrozenVec { fn from(vec: Vec) -> Self { Self {