about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/sync
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-09-08 14:14:57 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-09-08 14:14:57 +0200
commitc83eba92518166b9e40f43b40683d74c919af0ed (patch)
treebd6af919d3257e483d84e7139a7a94e6a55021e2 /compiler/rustc_data_structures/src/sync
parentf49382c0508db608aa9c33d6a8c77d2955d8f62c (diff)
downloadrust-c83eba92518166b9e40f43b40683d74c919af0ed.tar.gz
rust-c83eba92518166b9e40f43b40683d74c919af0ed.zip
Add Freeze::clone
Diffstat (limited to 'compiler/rustc_data_structures/src/sync')
-rw-r--r--compiler/rustc_data_structures/src/sync/freeze.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sync/freeze.rs b/compiler/rustc_data_structures/src/sync/freeze.rs
index ad71ae1af51..58ab91237f4 100644
--- a/compiler/rustc_data_structures/src/sync/freeze.rs
+++ b/compiler/rustc_data_structures/src/sync/freeze.rs
@@ -45,6 +45,16 @@ impl<T> FreezeLock<T> {
         }
     }
 
+    /// Clones the inner value along with the frozen state.
+    #[inline]
+    pub fn clone(&self) -> Self
+    where
+        T: Clone,
+    {
+        let lock = self.read();
+        Self::with(lock.clone(), self.is_frozen())
+    }
+
     #[inline]
     pub fn is_frozen(&self) -> bool {
         self.frozen.load(Ordering::Acquire)