From aad33198ff9096a3671cc4938f4b7dba983617be Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 14 Mar 2023 11:30:23 +0000 Subject: [PATCH] Remove a fishy Clone impl --- compiler/rustc_data_structures/src/sync.rs | 8 -------- .../rustc_middle/src/mir/interpret/mod.rs | 3 ++- compiler/rustc_query_system/src/cache.rs | 7 ++++++- compiler/rustc_span/src/lib.rs | 20 ++++++++++++++++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index 4e2126fff7b..9e9c3c6b9d7 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -481,14 +481,6 @@ impl Default for Lock { } } -// FIXME: Probably a bad idea -impl Clone for Lock { - #[inline] - fn clone(&self) -> Self { - Lock::new(self.borrow().clone()) - } -} - #[derive(Debug, Default)] pub struct RwLock(InnerRwLock); diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index 1766d7a6698..1f8b650e34c 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -263,7 +263,8 @@ impl AllocDecodingState { } pub fn new(data_offsets: Vec) -> Self { - let decoding_state = vec![Lock::new(State::Empty); data_offsets.len()]; + let decoding_state = + std::iter::repeat_with(|| Lock::new(State::Empty)).take(data_offsets.len()).collect(); Self { decoding_state, data_offsets } } diff --git a/compiler/rustc_query_system/src/cache.rs b/compiler/rustc_query_system/src/cache.rs index 7cc885be2ba..6e862db0b25 100644 --- a/compiler/rustc_query_system/src/cache.rs +++ b/compiler/rustc_query_system/src/cache.rs @@ -7,11 +7,16 @@ use rustc_data_structures::sync::Lock; use std::hash::Hash; -#[derive(Clone)] pub struct Cache { hashmap: Lock>>, } +impl Clone for Cache { + fn clone(&self) -> Self { + Self { hashmap: Lock::new(self.hashmap.borrow().clone()) } + } +} + impl Default for Cache { fn default() -> Self { Self { hashmap: Default::default() } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index e14760aa018..11cd5811be8 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1318,7 +1318,6 @@ pub struct SourceFileDiffs { } /// A single source in the [`SourceMap`]. -#[derive(Clone)] pub struct SourceFile { /// The name of the file that the source came from. Source that doesn't /// originate from files has names between angle brackets by convention @@ -1349,6 +1348,25 @@ pub struct SourceFile { pub cnum: CrateNum, } +impl Clone for SourceFile { + fn clone(&self) -> Self { + Self { + name: self.name.clone(), + src: self.src.clone(), + src_hash: self.src_hash.clone(), + external_src: Lock::new(self.external_src.borrow().clone()), + start_pos: self.start_pos.clone(), + end_pos: self.end_pos.clone(), + lines: Lock::new(self.lines.borrow().clone()), + multibyte_chars: self.multibyte_chars.clone(), + non_narrow_chars: self.non_narrow_chars.clone(), + normalized_pos: self.normalized_pos.clone(), + name_hash: self.name_hash.clone(), + cnum: self.cnum.clone(), + } + } +} + impl Encodable for SourceFile { fn encode(&self, s: &mut S) { self.name.encode(s);