Remove a fishy Clone impl

This commit is contained in:
Oli Scherer 2023-03-14 11:30:23 +00:00
parent 35d06f9c74
commit aad33198ff
4 changed files with 27 additions and 11 deletions

View File

@ -481,14 +481,6 @@ impl<T: Default> Default for Lock<T> {
}
}
// FIXME: Probably a bad idea
impl<T: Clone> Clone for Lock<T> {
#[inline]
fn clone(&self) -> Self {
Lock::new(self.borrow().clone())
}
}
#[derive(Debug, Default)]
pub struct RwLock<T>(InnerRwLock<T>);

View File

@ -263,7 +263,8 @@ impl AllocDecodingState {
}
pub fn new(data_offsets: Vec<u32>) -> 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 }
}

View File

@ -7,11 +7,16 @@ use rustc_data_structures::sync::Lock;
use std::hash::Hash;
#[derive(Clone)]
pub struct Cache<Key, Value> {
hashmap: Lock<FxHashMap<Key, WithDepNode<Value>>>,
}
impl<Key: Clone, Value: Clone> Clone for Cache<Key, Value> {
fn clone(&self) -> Self {
Self { hashmap: Lock::new(self.hashmap.borrow().clone()) }
}
}
impl<Key, Value> Default for Cache<Key, Value> {
fn default() -> Self {
Self { hashmap: Default::default() }

View File

@ -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<S: Encoder> Encodable<S> for SourceFile {
fn encode(&self, s: &mut S) {
self.name.encode(s);