Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit a31381f

Browse files
committed
Clippy
1 parent 53e3edb commit a31381f

File tree

100 files changed

+540
-496
lines changed

Some content is hidden

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

100 files changed

+540
-496
lines changed

account-decoder/src/parse_account_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn parse_account_data(
8181
) -> Result<ParsedAccount, ParseAccountError> {
8282
let program_name = PARSABLE_PROGRAM_IDS
8383
.get(program_id)
84-
.ok_or_else(|| ParseAccountError::ProgramNotParsable)?;
84+
.ok_or(ParseAccountError::ProgramNotParsable)?;
8585
let additional_data = additional_data.unwrap_or_default();
8686
let parsed_json = match program_name {
8787
ParsableAccount::Config => serde_json::to_value(parse_config(data, pubkey)?)?,

account-decoder/src/parse_sysvar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ mod test {
217217
account::create_account, fee_calculator::FeeCalculator, hash::Hash,
218218
sysvar::recent_blockhashes::IterItem,
219219
};
220-
use std::iter::FromIterator;
221220

222221
#[test]
223222
fn test_parse_sysvars() {
@@ -250,8 +249,9 @@ mod test {
250249
let fee_calculator = FeeCalculator {
251250
lamports_per_signature: 10,
252251
};
253-
let recent_blockhashes =
254-
RecentBlockhashes::from_iter(vec![IterItem(0, &hash, &fee_calculator)].into_iter());
252+
let recent_blockhashes: RecentBlockhashes = vec![IterItem(0, &hash, &fee_calculator)]
253+
.into_iter()
254+
.collect();
255255
let recent_blockhashes_sysvar = create_account(&recent_blockhashes, 1);
256256
assert_eq!(
257257
parse_sysvar(

account-decoder/src/parse_vote.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ mod test {
130130
let mut vote_account_data: Vec<u8> = vec![0; VoteState::size_of()];
131131
let versioned = VoteStateVersions::Current(Box::new(vote_state));
132132
VoteState::serialize(&versioned, &mut vote_account_data).unwrap();
133-
let mut expected_vote_state = UiVoteState::default();
134-
expected_vote_state.node_pubkey = Pubkey::default().to_string();
135-
expected_vote_state.authorized_withdrawer = Pubkey::default().to_string();
133+
let expected_vote_state = UiVoteState {
134+
node_pubkey: Pubkey::default().to_string(),
135+
authorized_withdrawer: Pubkey::default().to_string(),
136+
..UiVoteState::default()
137+
};
136138
assert_eq!(
137139
parse_vote(&vote_account_data).unwrap(),
138140
VoteAccountType::Vote(expected_vote_state)

bench-exchange/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
163163
)
164164
}
165165

166-
pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
166+
#[allow(clippy::field_reassign_with_default)]
167+
pub fn extract_args(matches: &ArgMatches) -> Config {
167168
let mut args = Config::default();
168169

169170
args.entrypoint_addr = solana_net_utils::parse_host_port(

bench-exchange/tests/bench_exchange.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ fn test_exchange_local_cluster() {
2222

2323
const NUM_NODES: usize = 1;
2424

25-
let mut config = Config::default();
26-
config.identity = Keypair::new();
27-
config.duration = Duration::from_secs(1);
28-
config.fund_amount = 100_000;
29-
config.threads = 1;
30-
config.transfer_delay = 20; // 15
31-
config.batch_size = 100; // 1000;
32-
config.chunk_size = 10; // 200;
33-
config.account_groups = 1; // 10;
25+
let config = Config {
26+
identity: Keypair::new(),
27+
duration: Duration::from_secs(1),
28+
fund_amount: 100_000,
29+
threads: 1,
30+
transfer_delay: 20, // 15
31+
batch_size: 100, // 1000
32+
chunk_size: 10, // 200
33+
account_groups: 1, // 10
34+
..Config::default()
35+
};
3436
let Config {
3537
fund_amount,
3638
batch_size,
@@ -89,15 +91,18 @@ fn test_exchange_bank_client() {
8991
bank.add_builtin("exchange_program", id(), process_instruction);
9092
let clients = vec![BankClient::new(bank)];
9193

92-
let mut config = Config::default();
93-
config.identity = identity;
94-
config.duration = Duration::from_secs(1);
95-
config.fund_amount = 100_000;
96-
config.threads = 1;
97-
config.transfer_delay = 20; // 0;
98-
config.batch_size = 100; // 1500;
99-
config.chunk_size = 10; // 1500;
100-
config.account_groups = 1; // 50;
101-
102-
do_bench_exchange(clients, config);
94+
do_bench_exchange(
95+
clients,
96+
Config {
97+
identity,
98+
duration: Duration::from_secs(1),
99+
fund_amount: 100_000,
100+
threads: 1,
101+
transfer_delay: 20, // 0;
102+
batch_size: 100, // 1500;
103+
chunk_size: 10, // 1500;
104+
account_groups: 1, // 50;
105+
..Config::default()
106+
},
107+
);
103108
}

bench-tps/src/bench.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,10 +938,12 @@ mod tests {
938938
let bank = Bank::new(&genesis_config);
939939
let client = Arc::new(BankClient::new(bank));
940940

941-
let mut config = Config::default();
942-
config.id = id;
943-
config.tx_count = 10;
944-
config.duration = Duration::from_secs(5);
941+
let config = Config {
942+
id,
943+
tx_count: 10,
944+
duration: Duration::from_secs(5),
945+
..Config::default()
946+
};
945947

946948
let keypair_count = config.tx_count * config.keypair_multiplier;
947949
let keypairs =

bench-tps/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
196196
/// * `matches` - command line arguments parsed by clap
197197
/// # Panics
198198
/// Panics if there is trouble parsing any of the arguments
199-
pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
199+
pub fn extract_args(matches: &ArgMatches) -> Config {
200200
let mut args = Config::default();
201201

202202
if let Some(addr) = matches.value_of("entrypoint") {

bench-tps/tests/bench_tps.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ fn test_bench_tps_local_cluster(config: Config) {
6060
#[test]
6161
#[serial]
6262
fn test_bench_tps_local_cluster_solana() {
63-
let mut config = Config::default();
64-
config.tx_count = 100;
65-
config.duration = Duration::from_secs(10);
66-
67-
test_bench_tps_local_cluster(config);
63+
test_bench_tps_local_cluster(Config {
64+
tx_count: 100,
65+
duration: Duration::from_secs(10),
66+
..Config::default()
67+
});
6868
}

ci/test-checks.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ _ "$cargo" stable fmt --all -- --check
5656

5757
# -Z... is needed because of clippy bug: https://github.com/rust-lang/rust-clippy/issues/4612
5858
# run nightly clippy for `sdk/` as there's a moderate amount of nightly-only code there
59-
_ "$cargo" nightly clippy \
60-
-Zunstable-options --workspace --all-targets \
61-
-- --deny=warnings --allow=clippy::stable_sort_primitive
59+
_ "$cargo" nightly clippy -Zunstable-options --workspace --all-targets -- --deny=warnings
6260

6361
cargo_audit_ignores=(
6462
# failure is officially deprecated/unmaintained
@@ -97,9 +95,7 @@ _ scripts/cargo-for-all-lock-files.sh +"$rust_stable" audit "${cargo_audit_ignor
9795
cd "$project"
9896
_ "$cargo" stable fmt -- --check
9997
_ "$cargo" nightly test
100-
_ "$cargo" nightly clippy -- --deny=warnings \
101-
--allow=clippy::missing_safety_doc \
102-
--allow=clippy::stable_sort_primitive
98+
_ "$cargo" nightly clippy -- --deny=warnings --allow=clippy::missing_safety_doc
10399
)
104100
done
105101
}

cli-output/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn build_balance_message(lamports: u64, use_lamports_unit: bool, show_unit:
2727

2828
// Pretty print a "name value"
2929
pub fn println_name_value(name: &str, value: &str) {
30-
let styled_value = if value == "" {
30+
let styled_value = if value.is_empty() {
3131
style("(not set)").italic()
3232
} else {
3333
style(value)
@@ -36,7 +36,7 @@ pub fn println_name_value(name: &str, value: &str) {
3636
}
3737

3838
pub fn writeln_name_value(f: &mut fmt::Formatter, name: &str, value: &str) -> fmt::Result {
39-
let styled_value = if value == "" {
39+
let styled_value = if value.is_empty() {
4040
style("(not set)").italic()
4141
} else {
4242
style(value)

cli/src/cli.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl CliConfig<'_> {
444444
) -> (SettingType, String) {
445445
settings
446446
.into_iter()
447-
.find(|(_, value)| value != "")
447+
.find(|(_, value)| !value.is_empty())
448448
.expect("no nonempty setting")
449449
}
450450

@@ -502,13 +502,14 @@ impl CliConfig<'_> {
502502
}
503503

504504
pub fn recent_for_tests() -> Self {
505-
let mut config = Self::default();
506-
config.commitment = CommitmentConfig::recent();
507-
config.send_transaction_config = RpcSendTransactionConfig {
508-
skip_preflight: true,
509-
..RpcSendTransactionConfig::default()
510-
};
511-
config
505+
Self {
506+
commitment: CommitmentConfig::recent(),
507+
send_transaction_config: RpcSendTransactionConfig {
508+
skip_preflight: true,
509+
..RpcSendTransactionConfig::default()
510+
},
511+
..Self::default()
512+
}
512513
}
513514
}
514515

@@ -995,6 +996,7 @@ fn process_confirm(
995996
}
996997
}
997998

999+
#[allow(clippy::unnecessary_wraps)]
9981000
fn process_decode_transaction(transaction: &Transaction) -> ProcessResult {
9991001
println_transaction(transaction, &None, "");
10001002
Ok("".to_string())
@@ -2763,9 +2765,11 @@ mod tests {
27632765
#[allow(clippy::cognitive_complexity)]
27642766
fn test_cli_process_command() {
27652767
// Success cases
2766-
let mut config = CliConfig::default();
2767-
config.rpc_client = Some(RpcClient::new_mock("succeeds".to_string()));
2768-
config.json_rpc_url = "http://127.0.0.1:8899".to_string();
2768+
let mut config = CliConfig {
2769+
rpc_client: Some(RpcClient::new_mock("succeeds".to_string())),
2770+
json_rpc_url: "http://127.0.0.1:8899".to_string(),
2771+
..CliConfig::default()
2772+
};
27692773

27702774
let keypair = Keypair::new();
27712775
let pubkey = keypair.pubkey().to_string();

cli/tests/stake.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,10 @@ fn test_stake_set_lockup() {
10971097
let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
10981098
let stake_account_pubkey = stake_keypair.pubkey();
10991099

1100-
let mut lockup = Lockup::default();
1101-
lockup.custodian = config.signers[0].pubkey();
1100+
let lockup = Lockup {
1101+
custodian: config.signers[0].pubkey(),
1102+
..Lockup::default()
1103+
};
11021104

11031105
config.signers.push(&stake_keypair);
11041106
config.command = CliCommand::CreateStakeAccount {

core/src/banking_stage.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,10 @@ mod tests {
11711171
Blockstore::open(&ledger_path)
11721172
.expect("Expected to be able to open database ledger"),
11731173
);
1174-
let mut poh_config = PohConfig::default();
1175-
poh_config.target_tick_count = Some(bank.max_tick_height() + num_extra_ticks);
1174+
let poh_config = PohConfig {
1175+
target_tick_count: Some(bank.max_tick_height() + num_extra_ticks),
1176+
..PohConfig::default()
1177+
};
11761178
let (exit, poh_recorder, poh_service, entry_receiver) =
11771179
create_test_recorder(&bank, &blockstore, Some(poh_config));
11781180
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
@@ -1236,9 +1238,12 @@ mod tests {
12361238
Blockstore::open(&ledger_path)
12371239
.expect("Expected to be able to open database ledger"),
12381240
);
1239-
let mut poh_config = PohConfig::default();
1240-
// limit tick count to avoid clearing working_bank at PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
1241-
poh_config.target_tick_count = Some(bank.max_tick_height() - 1);
1241+
let poh_config = PohConfig {
1242+
// limit tick count to avoid clearing working_bank at PohRecord then
1243+
// PohRecorderError(MaxHeightReached) at BankingStage
1244+
target_tick_count: Some(bank.max_tick_height() - 1),
1245+
..PohConfig::default()
1246+
};
12421247
let (exit, poh_recorder, poh_service, entry_receiver) =
12431248
create_test_recorder(&bank, &blockstore, Some(poh_config));
12441249
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
@@ -1381,9 +1386,12 @@ mod tests {
13811386
Blockstore::open(&ledger_path)
13821387
.expect("Expected to be able to open database ledger"),
13831388
);
1384-
let mut poh_config = PohConfig::default();
1385-
// limit tick count to avoid clearing working_bank at PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
1386-
poh_config.target_tick_count = Some(bank.max_tick_height() - 1);
1389+
let poh_config = PohConfig {
1390+
// limit tick count to avoid clearing working_bank at
1391+
// PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
1392+
target_tick_count: Some(bank.max_tick_height() - 1),
1393+
..PohConfig::default()
1394+
};
13871395
let (exit, poh_recorder, poh_service, entry_receiver) =
13881396
create_test_recorder(&bank, &blockstore, Some(poh_config));
13891397
let cluster_info =
@@ -1973,7 +1981,7 @@ mod tests {
19731981

19741982
assert_eq!(processed_transactions_count, 0,);
19751983

1976-
retryable_txs.sort();
1984+
retryable_txs.sort_unstable();
19771985
let expected: Vec<usize> = (0..transactions.len()).collect();
19781986
assert_eq!(retryable_txs, expected);
19791987
}

core/src/broadcast_stage.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! A stage to broadcast data from a leader node to validators
2+
#![allow(clippy::rc_buffer)]
23
use self::{
34
broadcast_fake_shreds_run::BroadcastFakeShredsRun, broadcast_metrics::*,
45
fail_entry_verification_broadcast_run::FailEntryVerificationBroadcastRun,
@@ -518,8 +519,10 @@ pub mod test {
518519

519520
#[test]
520521
fn test_num_live_peers() {
521-
let mut ci = ContactInfo::default();
522-
ci.wallclock = std::u64::MAX;
522+
let mut ci = ContactInfo {
523+
wallclock: std::u64::MAX,
524+
..ContactInfo::default()
525+
};
523526
assert_eq!(num_live_peers(&[ci.clone()]), 1);
524527
ci.wallclock = timestamp() - 1;
525528
assert_eq!(num_live_peers(&[ci.clone()]), 2);

core/src/broadcast_stage/broadcast_metrics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,9 @@ mod test {
270270
}
271271

272272
assert!(slot_broadcast_stats.lock().unwrap().0.get(&slot).is_none());
273-
let (returned_count, returned_slot, returned_instant) = receiver.recv().unwrap();
273+
let (returned_count, returned_slot, _returned_instant) = receiver.recv().unwrap();
274274
assert_eq!(returned_count, num_threads);
275275
assert_eq!(returned_slot, slot);
276-
assert_eq!(returned_instant, returned_instant);
277276
}
278277
}
279278
}

core/src/broadcast_stage/standard_broadcast_run.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::rc_buffer)]
2+
13
use super::{
24
broadcast_utils::{self, ReceiveResults},
35
*,
@@ -284,7 +286,7 @@ impl StandardBroadcastRun {
284286
blockstore: &Arc<Blockstore>,
285287
shreds: Arc<Vec<Shred>>,
286288
broadcast_shred_batch_info: Option<BroadcastShredBatchInfo>,
287-
) -> Result<()> {
289+
) {
288290
// Insert shreds into blockstore
289291
let insert_shreds_start = Instant::now();
290292
// The first shred is inserted synchronously
@@ -302,7 +304,6 @@ impl StandardBroadcastRun {
302304
num_shreds: shreds.len(),
303305
};
304306
self.update_insertion_metrics(&new_insert_shreds_stats, &broadcast_shred_batch_info);
305-
Ok(())
306307
}
307308

308309
fn update_insertion_metrics(
@@ -438,7 +439,8 @@ impl BroadcastRun for StandardBroadcastRun {
438439
blockstore: &Arc<Blockstore>,
439440
) -> Result<()> {
440441
let (shreds, slot_start_ts) = receiver.lock().unwrap().recv()?;
441-
self.insert(blockstore, shreds, slot_start_ts)
442+
self.insert(blockstore, shreds, slot_start_ts);
443+
Ok(())
442444
}
443445
}
444446

core/src/cluster_info.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ impl ClusterInfo {
884884
))
885885
})
886886
.collect();
887-
current_slots.sort();
887+
current_slots.sort_unstable();
888888
let min_slot: Slot = current_slots
889889
.iter()
890890
.map(|((_, s), _)| *s)
@@ -4139,8 +4139,10 @@ mod tests {
41394139

41404140
#[test]
41414141
fn test_protocol_sanitize() {
4142-
let mut pd = PruneData::default();
4143-
pd.wallclock = MAX_WALLCLOCK;
4142+
let pd = PruneData {
4143+
wallclock: MAX_WALLCLOCK,
4144+
..PruneData::default()
4145+
};
41444146
let msg = Protocol::PruneMessage(Pubkey::default(), pd);
41454147
assert_eq!(msg.sanitize(), Err(SanitizeError::ValueOutOfBounds));
41464148
}

0 commit comments

Comments
 (0)