diff --git a/compiler/rustc_data_structures/src/sync/freeze.rs b/compiler/rustc_data_structures/src/sync/freeze.rs index ad71ae1af5172..58ab91237f46d 100644 --- a/compiler/rustc_data_structures/src/sync/freeze.rs +++ b/compiler/rustc_data_structures/src/sync/freeze.rs @@ -45,6 +45,16 @@ impl FreezeLock { } } + /// 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) diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 8976ee83c4e76..3a869a2410aab 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1367,16 +1367,10 @@ impl Clone for SourceFile { name: self.name.clone(), src: self.src.clone(), src_hash: self.src_hash, - external_src: { - let lock = self.external_src.read(); - FreezeLock::with(lock.clone(), self.external_src.is_frozen()) - }, + external_src: self.external_src.clone(), start_pos: self.start_pos, source_len: self.source_len, - lines: { - let lock = self.lines.read(); - FreezeLock::with(lock.clone(), self.lines.is_frozen()) - }, + lines: self.lines.clone(), multibyte_chars: self.multibyte_chars.clone(), non_narrow_chars: self.non_narrow_chars.clone(), normalized_pos: self.normalized_pos.clone(),