Skip to content

Commit aad3319

Browse files
committed
Remove a fishy Clone impl
1 parent 35d06f9 commit aad3319

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

compiler/rustc_data_structures/src/sync.rs

-8
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,6 @@ impl<T: Default> Default for Lock<T> {
481481
}
482482
}
483483

484-
// FIXME: Probably a bad idea
485-
impl<T: Clone> Clone for Lock<T> {
486-
#[inline]
487-
fn clone(&self) -> Self {
488-
Lock::new(self.borrow().clone())
489-
}
490-
}
491-
492484
#[derive(Debug, Default)]
493485
pub struct RwLock<T>(InnerRwLock<T>);
494486

compiler/rustc_middle/src/mir/interpret/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ impl AllocDecodingState {
263263
}
264264

265265
pub fn new(data_offsets: Vec<u32>) -> Self {
266-
let decoding_state = vec![Lock::new(State::Empty); data_offsets.len()];
266+
let decoding_state =
267+
std::iter::repeat_with(|| Lock::new(State::Empty)).take(data_offsets.len()).collect();
267268

268269
Self { decoding_state, data_offsets }
269270
}

compiler/rustc_query_system/src/cache.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ use rustc_data_structures::sync::Lock;
77

88
use std::hash::Hash;
99

10-
#[derive(Clone)]
1110
pub struct Cache<Key, Value> {
1211
hashmap: Lock<FxHashMap<Key, WithDepNode<Value>>>,
1312
}
1413

14+
impl<Key: Clone, Value: Clone> Clone for Cache<Key, Value> {
15+
fn clone(&self) -> Self {
16+
Self { hashmap: Lock::new(self.hashmap.borrow().clone()) }
17+
}
18+
}
19+
1520
impl<Key, Value> Default for Cache<Key, Value> {
1621
fn default() -> Self {
1722
Self { hashmap: Default::default() }

compiler/rustc_span/src/lib.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,6 @@ pub struct SourceFileDiffs {
13181318
}
13191319

13201320
/// A single source in the [`SourceMap`].
1321-
#[derive(Clone)]
13221321
pub struct SourceFile {
13231322
/// The name of the file that the source came from. Source that doesn't
13241323
/// originate from files has names between angle brackets by convention
@@ -1349,6 +1348,25 @@ pub struct SourceFile {
13491348
pub cnum: CrateNum,
13501349
}
13511350

1351+
impl Clone for SourceFile {
1352+
fn clone(&self) -> Self {
1353+
Self {
1354+
name: self.name.clone(),
1355+
src: self.src.clone(),
1356+
src_hash: self.src_hash.clone(),
1357+
external_src: Lock::new(self.external_src.borrow().clone()),
1358+
start_pos: self.start_pos.clone(),
1359+
end_pos: self.end_pos.clone(),
1360+
lines: Lock::new(self.lines.borrow().clone()),
1361+
multibyte_chars: self.multibyte_chars.clone(),
1362+
non_narrow_chars: self.non_narrow_chars.clone(),
1363+
normalized_pos: self.normalized_pos.clone(),
1364+
name_hash: self.name_hash.clone(),
1365+
cnum: self.cnum.clone(),
1366+
}
1367+
}
1368+
}
1369+
13521370
impl<S: Encoder> Encodable<S> for SourceFile {
13531371
fn encode(&self, s: &mut S) {
13541372
self.name.encode(s);

0 commit comments

Comments
 (0)