Skip to content

Commit f61ea59

Browse files
authored
Merge pull request #6410 from jferrant/chore/remove-blanket-copy-from-impl-array-newtype
Remove blanket copy/clone from impl_array_newtype
2 parents 1393537 + 58bdb8d commit f61ea59

File tree

195 files changed

+1553
-1644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+1553
-1644
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
stacks-node = "run --package stacks-node --"
33
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
44
clippy-stacks = "clippy -p stx-genesis -p libstackerdb -p stacks-signer -p pox-locking -p clarity-serialization -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings"
5-
clippy-stackslib = "clippy -p stackslib --no-deps -- -Aclippy::all -Wclippy::indexing_slicing -Wclippy::nonminimal_bool"
5+
clippy-stackslib = "clippy -p stackslib --no-deps -- -Aclippy::all -Wclippy::indexing_slicing -Wclippy::nonminimal_bool -Wclippy::clone_on_copy"
66

77
# Uncomment to improve performance slightly, at the cost of portability
88
# * Note that native binaries may not run on CPUs that are different from the build machine

libsigner/src/tests/signer_state.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl SignerStateTest {
112112
self.active_signer_protocol_version,
113113
self.local_supported_signer_protocol_version,
114114
StateMachineUpdateContent::V1 {
115-
burn_block: self.burn_block,
115+
burn_block: self.burn_block.clone(),
116116
burn_block_height: self.burn_block_height,
117117
current_miner: self.current_miner.clone(),
118118
replay_transactions: transactions,
@@ -219,7 +219,7 @@ fn determine_latest_supported_signer_protocol_versions() {
219219
active_signer_protocol_version,
220220
new_version,
221221
StateMachineUpdateContent::V0 {
222-
burn_block,
222+
burn_block: burn_block.clone(),
223223
burn_block_height,
224224
current_miner: current_miner.clone(),
225225
},
@@ -286,17 +286,17 @@ fn determine_global_burn_views() {
286286

287287
assert_eq!(
288288
global_eval.determine_global_burn_view().unwrap(),
289-
(burn_block, burn_block_height)
289+
(&burn_block, burn_block_height)
290290
);
291291

292292
// Let's update 3 signers (60 percent) to support a new burn block view
293293
let new_update = StateMachineUpdateMessage::new(
294294
active_signer_protocol_version,
295295
local_supported_signer_protocol_version,
296296
StateMachineUpdateContent::V0 {
297-
burn_block,
297+
burn_block: burn_block.clone(),
298298
burn_block_height: burn_block_height.wrapping_add(1),
299-
current_miner: current_miner.clone(),
299+
current_miner,
300300
},
301301
)
302302
.unwrap();
@@ -313,7 +313,7 @@ fn determine_global_burn_views() {
313313
global_eval.insert_update(local_address, new_update);
314314
assert_eq!(
315315
global_eval.determine_global_burn_view().unwrap(),
316-
(burn_block, burn_block_height.wrapping_add(1))
316+
(&burn_block, burn_block_height.wrapping_add(1))
317317
);
318318
}
319319

@@ -344,9 +344,9 @@ fn determine_global_states() {
344344
};
345345

346346
let state_machine = SignerStateMachine {
347-
burn_block,
347+
burn_block: burn_block.clone(),
348348
burn_block_height,
349-
current_miner: (&current_miner).into(),
349+
current_miner: current_miner.clone().into(),
350350
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
351351
tx_replay_set: ReplayTransactionSet::none(),
352352
};
@@ -365,7 +365,7 @@ fn determine_global_states() {
365365
active_signer_protocol_version,
366366
local_supported_signer_protocol_version,
367367
StateMachineUpdateContent::V0 {
368-
burn_block,
368+
burn_block: burn_block.clone(),
369369
burn_block_height,
370370
current_miner: new_miner.clone(),
371371
},
@@ -385,7 +385,7 @@ fn determine_global_states() {
385385
let state_machine = SignerStateMachine {
386386
burn_block,
387387
burn_block_height,
388-
current_miner: (&new_miner).into(),
388+
current_miner: new_miner.into(),
389389
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
390390
tx_replay_set: ReplayTransactionSet::none(),
391391
};
@@ -425,7 +425,7 @@ fn determine_global_states_with_tx_replay_set() {
425425
let state_machine = SignerStateMachine {
426426
burn_block,
427427
burn_block_height,
428-
current_miner: (&current_miner).into(),
428+
current_miner: current_miner.clone().into(),
429429
active_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
430430
tx_replay_set: ReplayTransactionSet::none(),
431431
};
@@ -460,9 +460,9 @@ fn determine_global_states_with_tx_replay_set() {
460460
global_eval.insert_update(local_address.clone(), no_tx_replay_set_update.clone());
461461

462462
let new_burn_view_state_machine = SignerStateMachine {
463-
burn_block,
463+
burn_block: burn_block.clone(),
464464
burn_block_height,
465-
current_miner: (&current_miner).into(),
465+
current_miner: current_miner.clone().into(),
466466
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
467467
tx_replay_set: ReplayTransactionSet::none(),
468468
};
@@ -493,7 +493,7 @@ fn determine_global_states_with_tx_replay_set() {
493493
active_signer_protocol_version,
494494
local_supported_signer_protocol_version,
495495
StateMachineUpdateContent::V1 {
496-
burn_block,
496+
burn_block: burn_block.clone(),
497497
burn_block_height,
498498
current_miner: current_miner.clone(),
499499
replay_transactions: vec![tx.clone()],
@@ -518,7 +518,7 @@ fn determine_global_states_with_tx_replay_set() {
518518
let tx_replay_state_machine = SignerStateMachine {
519519
burn_block,
520520
burn_block_height,
521-
current_miner: (&current_miner).into(),
521+
current_miner: current_miner.into(),
522522
active_signer_protocol_version,
523523
tx_replay_set: ReplayTransactionSet::new(vec![tx]),
524524
};

libsigner/src/v0/messages.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,10 +1238,10 @@ impl BlockResponse {
12381238
}
12391239

12401240
/// Get the signer signature hash from the block response
1241-
pub fn get_signer_signature_hash(&self) -> Sha512Trunc256Sum {
1241+
pub fn get_signer_signature_hash(&self) -> &Sha512Trunc256Sum {
12421242
match self {
1243-
BlockResponse::Accepted(accepted) => accepted.signer_signature_hash,
1244-
BlockResponse::Rejected(rejection) => rejection.signer_signature_hash,
1243+
BlockResponse::Accepted(accepted) => &accepted.signer_signature_hash,
1244+
BlockResponse::Rejected(rejection) => &rejection.signer_signature_hash,
12451245
}
12461246
}
12471247

libsigner/src/v0/signer_state.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl GlobalStateEvaluator {
5353
}
5454

5555
/// Determine what the maximum signer protocol version that a majority of signers can support
56-
pub fn determine_latest_supported_signer_protocol_version(&mut self) -> Option<u64> {
56+
pub fn determine_latest_supported_signer_protocol_version(&self) -> Option<u64> {
5757
let mut protocol_versions = HashMap::new();
5858
for (address, update) in &self.address_updates {
5959
let Some(weight) = self.address_weights.get(address) else {
@@ -78,7 +78,7 @@ impl GlobalStateEvaluator {
7878
}
7979

8080
/// Determine what the global burn view is if there is one
81-
pub fn determine_global_burn_view(&mut self) -> Option<(ConsensusHash, u64)> {
81+
pub fn determine_global_burn_view(&self) -> Option<(&ConsensusHash, u64)> {
8282
let mut burn_blocks = HashMap::new();
8383
for (address, update) in &self.address_updates {
8484
let Some(weight) = self.address_weights.get(address) else {
@@ -91,14 +91,14 @@ impl GlobalStateEvaluator {
9191
.or_insert_with(|| 0);
9292
*entry += weight;
9393
if self.reached_agreement(*entry) {
94-
return Some((*burn_block, burn_block_height));
94+
return Some((burn_block, burn_block_height));
9595
}
9696
}
9797
None
9898
}
9999

100100
/// Check if there is an agreed upon global state
101-
pub fn determine_global_state(&mut self) -> Option<SignerStateMachine> {
101+
pub fn determine_global_state(&self) -> Option<SignerStateMachine> {
102102
let active_signer_protocol_version =
103103
self.determine_latest_supported_signer_protocol_version()?;
104104
let mut state_views = HashMap::new();
@@ -114,9 +114,9 @@ impl GlobalStateEvaluator {
114114
let tx_replay_set = update.content.tx_replay_set();
115115

116116
let state_machine = SignerStateMachine {
117-
burn_block: *burn_block,
117+
burn_block: burn_block.clone(),
118118
burn_block_height,
119-
current_miner: current_miner.into(),
119+
current_miner: current_miner.clone().into(),
120120
active_signer_protocol_version,
121121
// We need to calculate the threshold for the tx_replay_set separately
122122
tx_replay_set: ReplayTransactionSet::none(),
@@ -396,9 +396,9 @@ pub enum MinerState {
396396
NoValidMiner,
397397
}
398398

399-
impl From<&StateMachineUpdateMinerState> for MinerState {
400-
fn from(val: &StateMachineUpdateMinerState) -> Self {
401-
match *val {
399+
impl From<StateMachineUpdateMinerState> for MinerState {
400+
fn from(val: StateMachineUpdateMinerState) -> Self {
401+
match val {
402402
StateMachineUpdateMinerState::NoValidMiner => MinerState::NoValidMiner,
403403
StateMachineUpdateMinerState::ActiveMiner {
404404
current_miner_pkh,

libstackerdb/src/libstackerdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl StackerDBChunkData {
213213
slot_id: self.slot_id,
214214
slot_version: self.slot_version,
215215
data_hash: self.data_hash(),
216-
signature: self.sig,
216+
signature: self.sig.clone(),
217217
}
218218
}
219219

stacks-common/src/deps_common/bitcoin/blockdata/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::util::uint::Uint256;
3232

3333
/// A block header, which contains all the block's information except
3434
/// the actual transactions
35-
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
35+
#[derive(PartialEq, Eq, Clone, Debug)]
3636
pub struct BlockHeader {
3737
/// The protocol version. Should always be 1.
3838
pub version: u32,

stacks-common/src/deps_common/bitcoin/blockdata/transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::deps_common::bitcoin::network::serialize::{
3636
use crate::deps_common::bitcoin::util::hash::Sha256dHash;
3737

3838
/// A reference to a transaction output
39-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
39+
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
4040
pub struct OutPoint {
4141
/// The referenced transaction's txid
4242
pub txid: Sha256dHash,
@@ -161,7 +161,7 @@ impl Transaction {
161161
.map(|txin| TxIn {
162162
script_sig: Script::new(),
163163
witness: vec![],
164-
..*txin
164+
..txin.clone()
165165
})
166166
.collect(),
167167
output: self.output.clone(),
@@ -228,7 +228,7 @@ impl Transaction {
228228
// Add all inputs necessary..
229229
if anyone_can_pay {
230230
tx.input = vec![TxIn {
231-
previous_output: self.input[input_index].previous_output,
231+
previous_output: self.input[input_index].previous_output.clone(),
232232
script_sig: script_pubkey.clone(),
233233
sequence: self.input[input_index].sequence,
234234
witness: vec![],
@@ -237,7 +237,7 @@ impl Transaction {
237237
tx.input = Vec::with_capacity(self.input.len());
238238
for (n, input) in self.input.iter().enumerate() {
239239
tx.input.push(TxIn {
240-
previous_output: input.previous_output,
240+
previous_output: input.previous_output.clone(),
241241
script_sig: if n == input_index {
242242
script_pubkey.clone()
243243
} else {

stacks-common/src/deps_common/bitcoin/util/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ pub fn bitcoin_merkle_root(data: Vec<Sha256dHash>) -> Sha256dHash {
433433
return Default::default();
434434
}
435435
if data.len() == 1 {
436-
return data[0];
436+
return data[0].clone();
437437
}
438438
// Recursion
439439
let iterations = data.len().div_ceil(2);

stacks-common/src/types/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub type StacksPublicKey = Secp256k1PublicKey;
3333
pub type StacksPrivateKey = Secp256k1PrivateKey;
3434

3535
/// Hash of a Trie node. This is a SHA2-512/256.
36-
#[derive(Default)]
36+
#[derive(Default, Copy)]
3737
pub struct TrieHash(pub [u8; 32]);
3838
impl_array_newtype!(TrieHash, u8, 32);
3939
impl_array_hexstring_fmt!(TrieHash);

stacks-common/src/util/macros.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,12 @@ macro_rules! impl_array_newtype {
427427
}
428428

429429
impl Clone for $thing {
430-
#[inline]
431-
fn clone(&self) -> $thing {
432-
*self
430+
#[allow(clippy::non_canonical_clone_impl)]
431+
fn clone(&self) -> Self {
432+
$thing(self.0.clone())
433433
}
434434
}
435435

436-
impl Copy for $thing {}
437-
438436
impl ::std::hash::Hash for $thing {
439437
#[inline]
440438
fn hash<H>(&self, state: &mut H)

0 commit comments

Comments
 (0)