Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ After changing Rust code (`*.rs`) follow these steps in order:
-D clippy::all \
-D clippy::mem_forget \
-D clippy::unseparated_literal_suffix \
-D clippy::redundant_clone \
-D clippy::needless_pass_by_value \
-A clippy::uninlined_format_args
```
where `<CRATES>` is a space separated list of
Expand Down Expand Up @@ -66,4 +68,4 @@ After the PR has been created or updated, request a review from the GitHub Copil
```
gh api repos/dfinity/ic/pulls/<PULL_REQUEST_NUMBER>/requested_reviewers --method POST --raw-field 'reviewers[]=copilot-pull-request-reviewer[bot]'
```
where `<PULL_REQUEST_NUMBER>` is the number of the Pull Request.
where `<PULL_REQUEST_NUMBER>` is the number of the Pull Request.
4 changes: 4 additions & 0 deletions ci/scripts/rust-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ clippy_args=(
# Require 42_u64, as opposed to 42u64. Because spaces good.
--deny clippy::unseparated_literal_suffix

# Avoid unnecessary clones and passes by value.
--deny clippy::redundant_clone
--deny clippy::needless_pass_by_value

# Allow format!("{}", x) instead of format!("{x}").
--allow clippy::uninlined_format_args
)
Expand Down
32 changes: 16 additions & 16 deletions packages/ic-heap-bytes/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,22 +713,22 @@ fn nested_vec_enum_struct_string() {
E::One,
E::Two(Some((
S {
v: vec!["!".to_string(), "!".repeat(3).to_string()],
m: BTreeMap::from([("!".repeat(5).to_string(), "!".repeat(7).to_string())]),
v: vec!["!".to_string(), "!".repeat(3)],
m: BTreeMap::from([("!".repeat(5), "!".repeat(7))]),
},
S {
v: vec!["!".repeat(11).to_string(), "!".repeat(13).to_string()],
m: BTreeMap::from([("!".repeat(17).to_string(), "!".repeat(19).to_string())]),
v: vec!["!".repeat(11), "!".repeat(13)],
m: BTreeMap::from([("!".repeat(17), "!".repeat(19))]),
},
))),
E::Three(vec![
Ok(S {
v: vec!["!".repeat(23).to_string(), "!".repeat(29).to_string()],
m: BTreeMap::from([("!".repeat(31).to_string(), "!".repeat(37).to_string())]),
v: vec!["!".repeat(23), "!".repeat(29)],
m: BTreeMap::from([("!".repeat(31), "!".repeat(37))]),
}),
Err(S {
v: vec!["!".repeat(41).to_string(), "!".repeat(43).to_string()],
m: BTreeMap::from([("!".repeat(47).to_string(), "!".repeat(53).to_string())]),
v: vec!["!".repeat(41), "!".repeat(43)],
m: BTreeMap::from([("!".repeat(47), "!".repeat(53))]),
}),
]),
];
Expand Down Expand Up @@ -779,22 +779,22 @@ fn with_vec_enum_struct_string() {
E::One,
E::Two(Some((
S {
v: vec!["!".to_string(), "!".repeat(3).to_string()],
m: BTreeMap::from([("!".repeat(5).to_string(), "!".repeat(7).to_string())]),
v: vec!["!".to_string(), "!".repeat(3)],
m: BTreeMap::from([("!".repeat(5), "!".repeat(7))]),
},
S {
v: vec!["!".repeat(11).to_string(), "!".repeat(13).to_string()],
m: BTreeMap::from([("!".repeat(17).to_string(), "!".repeat(19).to_string())]),
v: vec!["!".repeat(11), "!".repeat(13)],
m: BTreeMap::from([("!".repeat(17), "!".repeat(19))]),
},
))),
E::Three(vec![
Ok(S {
v: vec!["!".repeat(23).to_string(), "!".repeat(29).to_string()],
m: BTreeMap::from([("!".repeat(31).to_string(), "!".repeat(37).to_string())]),
v: vec!["!".repeat(23), "!".repeat(29)],
m: BTreeMap::from([("!".repeat(31), "!".repeat(37))]),
}),
Err(S {
v: vec!["!".repeat(41).to_string(), "!".repeat(43).to_string()],
m: BTreeMap::from([("!".repeat(47).to_string(), "!".repeat(53).to_string())]),
v: vec!["!".repeat(41), "!".repeat(43)],
m: BTreeMap::from([("!".repeat(47), "!".repeat(53))]),
}),
]),
];
Expand Down
4 changes: 2 additions & 2 deletions packages/ic-pub-key/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn test_vetkd_derivation_using_test_key_1() {
let args = VetKDPublicKeyArgs {
canister_id: Some(canister_id),
context: b"context-string".to_vec(),
key_id: key_id.clone(),
key_id,
};

let derived_key = derive_vetkd_key(&args).unwrap();
Expand Down Expand Up @@ -446,7 +446,7 @@ fn test_vetkd_derivation_using_key1() {
let args = VetKDPublicKeyArgs {
canister_id: Some(canister_id),
context: vec![],
key_id: key_id.clone(),
key_id,
};

let canister_key = derive_vetkd_key(&args).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion packages/ic-secp256k1/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ fn key_derivation_matches_bip32() {

let bip32_mk = bip32::XPub::try_from(ext).expect("Failed to accept BIP32");

let mut bip32_state = bip32_mk.clone();
let mut bip32_state = bip32_mk;
for (i, p) in path.iter().enumerate() {
let derived = bip32_state
.derive_child(bip32::ChildNumber(*p))
Expand Down
9 changes: 3 additions & 6 deletions packages/icrc-ledger-types/src/icrc21/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ impl ConsentMessage {
ConsentMessage::GenericDisplayMessage(message) => {
message.push_str(&format!("\n\n**{name}:**\n`{account}`"))
}
ConsentMessage::FieldsDisplayMessage(fields_display) => fields_display.fields.push((
name.to_string(),
Value::Text {
content: account.to_string(),
},
)),
ConsentMessage::FieldsDisplayMessage(fields_display) => fields_display
.fields
.push((name.to_string(), Value::Text { content: account })),
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/pocket-ic/tests/canister_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_canister_snapshot_download_upload(pic: &mut PocketIc, canister_id: Princ
pic.canister_snapshot_download(
canister_id,
Principal::anonymous(),
uploaded_snapshot_id.clone(),
uploaded_snapshot_id,
uploaded_snapshot_dir.clone(),
);

Expand Down Expand Up @@ -138,14 +138,14 @@ fn test_canister_snapshot_download_upload(pic: &mut PocketIc, canister_id: Princ
.arg("--identity")
.arg("anonymous")
.current_dir(dfx_home_dir.clone())
.env("HOME", dfx_home_dir.clone())
.env("HOME", dfx_home_dir)
.output()
.unwrap();

// Check that the snapshots downloaded using PocketIC and dfx are equal.
let diff = Command::new("diff")
.arg("-r")
.arg(downloaded_snapshot_dir.clone())
.arg(downloaded_snapshot_dir)
.arg(dfx_snapshot_dir.clone())
.output()
.expect("Failed to execute diff");
Expand Down
2 changes: 1 addition & 1 deletion packages/pocket-ic/tests/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ fn create_instance_twice() {
let status_endpoint = url.join("api/v2/status").unwrap();

// Check that the server is running.
let response = client.get(status_endpoint.clone()).send().unwrap();
let response = client.get(status_endpoint).send().unwrap();
assert_eq!(response.status(), 200);
}
10 changes: 5 additions & 5 deletions packages/pocket-ic/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn test_install_canister_with_no_cycles() {
let pic = PocketIc::new();
let canister_id = pic.create_canister();
let wasm = b"\x00\x61\x73\x6d\x01\x00\x00\x00".to_vec();
pic.install_canister(canister_id, wasm.clone(), vec![], None);
pic.install_canister(canister_id, wasm, vec![], None);
}

#[test]
Expand Down Expand Up @@ -1249,7 +1249,7 @@ fn test_ecdsa_disabled() {
&pic,
canister,
"sign_with_ecdsa",
(message_hash.clone(), derivation_path, key_id),
(message_hash, derivation_path, key_id),
)
.unwrap()
.0
Expand Down Expand Up @@ -1452,7 +1452,7 @@ fn test_canister_http_with_transform() {
response: CanisterHttpResponse::CanisterHttpReply(CanisterHttpReply {
status: 200,
headers: vec![],
body: body.clone(),
body,
}),
additional_responses: vec![],
};
Expand Down Expand Up @@ -1578,7 +1578,7 @@ fn test_canister_http_with_one_additional_response() {
additional_responses: vec![CanisterHttpResponse::CanisterHttpReply(CanisterHttpReply {
status: 200,
headers: vec![],
body: body.clone(),
body,
})],
};
pic.mock_canister_http_response(mock_canister_http_response);
Expand Down Expand Up @@ -2229,7 +2229,7 @@ fn read_state_request_status(
msg_id: &[u8],
) -> reqwest::blocking::Response {
let path = vec!["request_status".into(), Label::from_bytes(msg_id)];
let paths = vec![path.clone()];
let paths = vec![path];
let content = ReadState {
ingress_expiry: pic.get_time().as_nanos_since_unix_epoch() + 240_000_000_000,
sender: Principal::anonymous(),
Expand Down
2 changes: 1 addition & 1 deletion packages/pocket-ic/tests/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ fn test_custom_blockmaker_metrics() {
registry_proto_path,
));
let latest_version = registry_data_provider.latest_version();
let registry_client = RegistryClientImpl::new(registry_data_provider.clone(), None);
let registry_client = RegistryClientImpl::new(registry_data_provider, None);
registry_client.poll_once().unwrap();
let node_ids = registry_client
.get_node_ids_on_subnet(
Expand Down
2 changes: 1 addition & 1 deletion rs/artifact_pool/src/canister_http_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
pool.insert(to_unvalidated(share1.clone()));

let result = pool.apply(vec![
CanisterHttpChangeAction::MoveToValidated(share2.clone()),
CanisterHttpChangeAction::MoveToValidated(share2),
CanisterHttpChangeAction::MoveToValidated(share1.clone()),
]);

Expand Down
6 changes: 3 additions & 3 deletions rs/artifact_pool/src/certification_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ mod tests {
.get_by_height(Height::from(1))
.next()
.unwrap();
assert_eq!(cert_from_pool, msg_to_cert(cert_msg.clone()));
assert_eq!(cert_from_pool, msg_to_cert(cert_msg));
})
}

Expand Down Expand Up @@ -774,8 +774,8 @@ mod tests {
]);
let share_msg = fake_share(10, 30);
let cert_msg = fake_cert(10);
pool.insert(to_unvalidated(share_msg.clone()));
pool.insert(to_unvalidated(cert_msg.clone()));
pool.insert(to_unvalidated(share_msg));
pool.insert(to_unvalidated(cert_msg));

assert_eq!(pool.all_heights_with_artifacts().len(), 1);
assert_eq!(pool.shares_at_height(Height::from(10)).count(), 1);
Expand Down
8 changes: 4 additions & 4 deletions rs/artifact_pool/src/consensus_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1773,12 +1773,12 @@ mod tests {
random_tape.clone().into_message(),
finalization.clone().into_message(),
finalization_at_4.into_message(),
notarization.clone().into_message(),
notarization.into_message(),
proposal.clone().into_message(),
proposal_non_final.clone().into_message(),
proposal3.clone().into_message(),
proposal_non_final.into_message(),
proposal3.into_message(),
notarization3.clone().into_message(),
proposal3_final.clone().into_message(),
proposal3_final.into_message(),
cup.clone().into_message(),
]
.into_iter()
Expand Down
4 changes: 1 addition & 3 deletions rs/artifact_pool/src/lmdb_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,9 +2650,7 @@ mod tests {
run_persistent_pool_test("test_purge_below_maximum_element", |config, log| {
const MAX_HEIGHT: Height = Height::new(10);
let mut pool = PersistentHeightIndexedPool::new_consensus_pool(
config.clone(),
/*read_only=*/ false,
log.clone(),
config, /*read_only=*/ false, log,
);
let rb_ops = random_beacon_ops(1..=MAX_HEIGHT.get());
pool.mutate(rb_ops.clone());
Expand Down
4 changes: 2 additions & 2 deletions rs/bitcoin/adapter/src/blockchainmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ pub mod test {
async fn test_ensure_sync_blocks_retries_timed_out_getdata_requests() {
let addr = SocketAddr::from_str("127.0.0.1:8333").expect("bad address format");
let sockets = vec![addr];
let mut channel = TestChannel::new(sockets.clone());
let mut channel = TestChannel::new(sockets);
let test_state = TestState::setup();
let block_1_hash = test_state.block_1.block_hash();
let (_, mut blockchain_manager) = create_blockchain_manager(Network::Bitcoin);
Expand Down Expand Up @@ -1245,7 +1245,7 @@ pub mod test {
let addr = SocketAddr::from_str("127.0.0.1:8333").expect("bad address format");
let addr2 = SocketAddr::from_str("127.0.0.1:3338").expect("bad address format");
let sockets = vec![addr];
let mut channel = TestChannel::new(sockets.clone());
let mut channel = TestChannel::new(sockets);
let test_state = TestState::setup();
let block_1_hash = test_state.block_1.block_hash();
let (_, mut blockchain_manager) = create_blockchain_manager(Network::Bitcoin);
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/adapter/src/blockchainstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ where
pub fn locator_hashes(&self) -> Vec<BlockHash> {
let mut hashes = Vec::new();
let tip = self.get_active_chain_tip();
let mut current_header = tip.header.clone();
let mut current_header = tip.header;
let mut current_hash = current_header.block_hash();
let mut step: u32 = 1;
let mut last_hash = current_hash;
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/adapter/test_utils/src/bitcoind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl<T: RpcClientType> Daemon<T> {
return Err(status);
}

let rpc_client = RpcClient::new(network, &rpc_url, auth.clone())
let rpc_client = RpcClient::new(network, &rpc_url, auth)
.map_err(DaemonStatus::ClientError)?
.ensure_wallet()
.map_err(DaemonStatus::ClientError)?;
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/adapter/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ fn test_bfs_order<T: RpcClientType + Into<AdapterNetwork>>() {
&fork_test_data1,
&fork_test_data2,
&adapter_client,
anchor.clone(),
anchor,
);
assert!(bfs_order1 == block_hashes || bfs_order2 == block_hashes);
}
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/checker/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub trait FetchEnv {
match self.http_get_tx(&provider, txid, max_response_bytes).await {
Ok(tx) => {
let input_addresses = tx.input.iter().map(|_| None).collect();
match TransactionCheckData::from_transaction(provider.btc_network(), tx.clone()) {
match TransactionCheckData::from_transaction(provider.btc_network(), tx) {
Ok(tx) => {
let fetched = FetchedTx {
tx,
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/checker/src/fetch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn test_try_fetch_tx() {
tx: from_tx(&mock_transaction()),
input_addresses: vec![None],
});
state::set_fetch_status(txid_0, fetched_0.clone());
state::set_fetch_status(txid_0, fetched_0);
assert!(matches!(
env.try_fetch_tx(txid_0),
TryFetchResult::Fetched(_)
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/checker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async fn check_transaction_with<F: FnOnce() -> Result<Txid, String>>(
fn transform(raw: TransformArgs) -> HttpRequestResult {
HttpRequestResult {
status: raw.response.status.clone(),
body: raw.response.body.clone(),
body: raw.response.body,
headers: vec![],
}
}
Expand Down
4 changes: 2 additions & 2 deletions rs/bitcoin/checker/src/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn btcscan_request(txid: Txid, max_response_bytes: u32) -> HttpRequestArgs {
value: "bitcoin_inputs_collector".to_string(),
}];
HttpRequestArgs {
url: url.to_string(),
url,
method: HttpMethod::GET,
body: None,
max_response_bytes: Some(max_response_bytes as u64),
Expand All @@ -144,7 +144,7 @@ fn make_get_request(
};
let request_headers = vec![];
HttpRequestArgs {
url: url.to_string(),
url,
method: HttpMethod::GET,
body: None,
max_response_bytes: Some(max_response_bytes as u64),
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/checker/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod schema_upgrades {

let serialized_config_before_upgrade = encode(&config_before_upgrade);
let config_after_upgrade: Config = decode(serialized_config_before_upgrade.as_slice());
assert_eq!(config_before_upgrade, config_after_upgrade.clone().into());
assert_eq!(config_before_upgrade, config_after_upgrade.into());
}
}

Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/ckbtc/minter/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod processable_utxos_for_account {
result,
(
ProcessableUtxos {
new_utxos: all_utxos.clone(),
new_utxos: all_utxos,
..Default::default()
},
vec![]
Expand Down
Loading
Loading