Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Dec 14, 2020
1 parent 0d139d7 commit 7143aaa
Show file tree
Hide file tree
Showing 102 changed files with 543 additions and 499 deletions.
2 changes: 1 addition & 1 deletion account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn parse_account_data(
) -> Result<ParsedAccount, ParseAccountError> {
let program_name = PARSABLE_PROGRAM_IDS
.get(program_id)
.ok_or_else(|| ParseAccountError::ProgramNotParsable)?;
.ok_or(ParseAccountError::ProgramNotParsable)?;
let additional_data = additional_data.unwrap_or_default();
let parsed_json = match program_name {
ParsableAccount::Config => serde_json::to_value(parse_config(data, pubkey)?)?,
Expand Down
6 changes: 3 additions & 3 deletions account-decoder/src/parse_sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ mod test {
account::create_account, fee_calculator::FeeCalculator, hash::Hash,
sysvar::recent_blockhashes::IterItem,
};
use std::iter::FromIterator;

#[test]
fn test_parse_sysvars() {
Expand Down Expand Up @@ -250,8 +249,9 @@ mod test {
let fee_calculator = FeeCalculator {
lamports_per_signature: 10,
};
let recent_blockhashes =
RecentBlockhashes::from_iter(vec![IterItem(0, &hash, &fee_calculator)].into_iter());
let recent_blockhashes: RecentBlockhashes = vec![IterItem(0, &hash, &fee_calculator)]
.into_iter()
.collect();
let recent_blockhashes_sysvar = create_account(&recent_blockhashes, 1);
assert_eq!(
parse_sysvar(
Expand Down
8 changes: 5 additions & 3 deletions account-decoder/src/parse_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ mod test {
let mut vote_account_data: Vec<u8> = vec![0; VoteState::size_of()];
let versioned = VoteStateVersions::Current(Box::new(vote_state));
VoteState::serialize(&versioned, &mut vote_account_data).unwrap();
let mut expected_vote_state = UiVoteState::default();
expected_vote_state.node_pubkey = Pubkey::default().to_string();
expected_vote_state.authorized_withdrawer = Pubkey::default().to_string();
let expected_vote_state = UiVoteState {
node_pubkey: Pubkey::default().to_string(),
authorized_withdrawer: Pubkey::default().to_string(),
..UiVoteState::default()
};
assert_eq!(
parse_vote(&vote_account_data).unwrap(),
VoteAccountType::Vote(expected_vote_state)
Expand Down
3 changes: 2 additions & 1 deletion bench-exchange/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
)
}

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

args.entrypoint_addr = solana_net_utils::parse_host_port(
Expand Down
45 changes: 25 additions & 20 deletions bench-exchange/tests/bench_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ fn test_exchange_local_cluster() {

const NUM_NODES: usize = 1;

let mut config = Config::default();
config.identity = Keypair::new();
config.duration = Duration::from_secs(1);
config.fund_amount = 100_000;
config.threads = 1;
config.transfer_delay = 20; // 15
config.batch_size = 100; // 1000;
config.chunk_size = 10; // 200;
config.account_groups = 1; // 10;
let config = Config {
identity: Keypair::new(),
duration: Duration::from_secs(1),
fund_amount: 100_000,
threads: 1,
transfer_delay: 20, // 15
batch_size: 100, // 1000
chunk_size: 10, // 200
account_groups: 1, // 10
..Config::default()
};
let Config {
fund_amount,
batch_size,
Expand Down Expand Up @@ -89,15 +91,18 @@ fn test_exchange_bank_client() {
bank.add_builtin("exchange_program", id(), process_instruction);
let clients = vec![BankClient::new(bank)];

let mut config = Config::default();
config.identity = identity;
config.duration = Duration::from_secs(1);
config.fund_amount = 100_000;
config.threads = 1;
config.transfer_delay = 20; // 0;
config.batch_size = 100; // 1500;
config.chunk_size = 10; // 1500;
config.account_groups = 1; // 50;

do_bench_exchange(clients, config);
do_bench_exchange(
clients,
Config {
identity,
duration: Duration::from_secs(1),
fund_amount: 100_000,
threads: 1,
transfer_delay: 20, // 0;
batch_size: 100, // 1500;
chunk_size: 10, // 1500;
account_groups: 1, // 50;
..Config::default()
},
);
}
10 changes: 6 additions & 4 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,12 @@ mod tests {
let bank = Bank::new(&genesis_config);
let client = Arc::new(BankClient::new(bank));

let mut config = Config::default();
config.id = id;
config.tx_count = 10;
config.duration = Duration::from_secs(5);
let config = Config {
id,
tx_count: 10,
duration: Duration::from_secs(5),
..Config::default()
};

let keypair_count = config.tx_count * config.keypair_multiplier;
let keypairs =
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
/// * `matches` - command line arguments parsed by clap
/// # Panics
/// Panics if there is trouble parsing any of the arguments
pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
pub fn extract_args(matches: &ArgMatches) -> Config {
let mut args = Config::default();

if let Some(addr) = matches.value_of("entrypoint") {
Expand Down
10 changes: 5 additions & 5 deletions bench-tps/tests/bench_tps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fn test_bench_tps_local_cluster(config: Config) {
#[test]
#[serial]
fn test_bench_tps_local_cluster_solana() {
let mut config = Config::default();
config.tx_count = 100;
config.duration = Duration::from_secs(10);

test_bench_tps_local_cluster(config);
test_bench_tps_local_cluster(Config {
tx_count: 100,
duration: Duration::from_secs(10),
..Config::default()
});
}
8 changes: 2 additions & 6 deletions ci/test-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ _ "$cargo" stable fmt --all -- --check

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

cargo_audit_ignores=(
# failure is officially deprecated/unmaintained
Expand Down Expand Up @@ -97,9 +95,7 @@ _ scripts/cargo-for-all-lock-files.sh +"$rust_stable" audit "${cargo_audit_ignor
cd "$project"
_ "$cargo" stable fmt -- --check
_ "$cargo" nightly test
_ "$cargo" nightly clippy -- --deny=warnings \
--allow=clippy::missing_safety_doc \
--allow=clippy::stable_sort_primitive
_ "$cargo" nightly clippy -- --deny=warnings --allow=clippy::missing_safety_doc
)
done
}
Expand Down
4 changes: 2 additions & 2 deletions cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn build_balance_message(lamports: u64, use_lamports_unit: bool, show_unit:

// Pretty print a "name value"
pub fn println_name_value(name: &str, value: &str) {
let styled_value = if value == "" {
let styled_value = if value.is_empty() {
style("(not set)").italic()
} else {
style(value)
Expand All @@ -36,7 +36,7 @@ pub fn println_name_value(name: &str, value: &str) {
}

pub fn writeln_name_value(f: &mut fmt::Formatter, name: &str, value: &str) -> fmt::Result {
let styled_value = if value == "" {
let styled_value = if value.is_empty() {
style("(not set)").italic()
} else {
style(value)
Expand Down
26 changes: 15 additions & 11 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl CliConfig<'_> {
) -> (SettingType, String) {
settings
.into_iter()
.find(|(_, value)| value != "")
.find(|(_, value)| !value.is_empty())
.expect("no nonempty setting")
}

Expand Down Expand Up @@ -502,13 +502,14 @@ impl CliConfig<'_> {
}

pub fn recent_for_tests() -> Self {
let mut config = Self::default();
config.commitment = CommitmentConfig::recent();
config.send_transaction_config = RpcSendTransactionConfig {
skip_preflight: true,
..RpcSendTransactionConfig::default()
};
config
Self {
commitment: CommitmentConfig::recent(),
send_transaction_config: RpcSendTransactionConfig {
skip_preflight: true,
..RpcSendTransactionConfig::default()
},
..Self::default()
}
}
}

Expand Down Expand Up @@ -995,6 +996,7 @@ fn process_confirm(
}
}

#[allow(clippy::unnecessary_wraps)]
fn process_decode_transaction(transaction: &Transaction) -> ProcessResult {
println_transaction(transaction, &None, "");
Ok("".to_string())
Expand Down Expand Up @@ -2763,9 +2765,11 @@ mod tests {
#[allow(clippy::cognitive_complexity)]
fn test_cli_process_command() {
// Success cases
let mut config = CliConfig::default();
config.rpc_client = Some(RpcClient::new_mock("succeeds".to_string()));
config.json_rpc_url = "http://127.0.0.1:8899".to_string();
let mut config = CliConfig {
rpc_client: Some(RpcClient::new_mock("succeeds".to_string())),
json_rpc_url: "http://127.0.0.1:8899".to_string(),
..CliConfig::default()
};

let keypair = Keypair::new();
let pubkey = keypair.pubkey().to_string();
Expand Down
6 changes: 4 additions & 2 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,10 @@ fn test_stake_set_lockup() {
let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
let stake_account_pubkey = stake_keypair.pubkey();

let mut lockup = Lockup::default();
lockup.custodian = config.signers[0].pubkey();
let lockup = Lockup {
custodian: config.signers[0].pubkey(),
..Lockup::default()
};

config.signers.push(&stake_keypair);
config.command = CliCommand::CreateStakeAccount {
Expand Down
26 changes: 17 additions & 9 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,10 @@ mod tests {
Blockstore::open(&ledger_path)
.expect("Expected to be able to open database ledger"),
);
let mut poh_config = PohConfig::default();
poh_config.target_tick_count = Some(bank.max_tick_height() + num_extra_ticks);
let poh_config = PohConfig {
target_tick_count: Some(bank.max_tick_height() + num_extra_ticks),
..PohConfig::default()
};
let (exit, poh_recorder, poh_service, entry_receiver) =
create_test_recorder(&bank, &blockstore, Some(poh_config));
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
Expand Down Expand Up @@ -1236,9 +1238,12 @@ mod tests {
Blockstore::open(&ledger_path)
.expect("Expected to be able to open database ledger"),
);
let mut poh_config = PohConfig::default();
// limit tick count to avoid clearing working_bank at PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
poh_config.target_tick_count = Some(bank.max_tick_height() - 1);
let poh_config = PohConfig {
// limit tick count to avoid clearing working_bank at PohRecord then
// PohRecorderError(MaxHeightReached) at BankingStage
target_tick_count: Some(bank.max_tick_height() - 1),
..PohConfig::default()
};
let (exit, poh_recorder, poh_service, entry_receiver) =
create_test_recorder(&bank, &blockstore, Some(poh_config));
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
Expand Down Expand Up @@ -1381,9 +1386,12 @@ mod tests {
Blockstore::open(&ledger_path)
.expect("Expected to be able to open database ledger"),
);
let mut poh_config = PohConfig::default();
// limit tick count to avoid clearing working_bank at PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
poh_config.target_tick_count = Some(bank.max_tick_height() - 1);
let poh_config = PohConfig {
// limit tick count to avoid clearing working_bank at
// PohRecord then PohRecorderError(MaxHeightReached) at BankingStage
target_tick_count: Some(bank.max_tick_height() - 1),
..PohConfig::default()
};
let (exit, poh_recorder, poh_service, entry_receiver) =
create_test_recorder(&bank, &blockstore, Some(poh_config));
let cluster_info =
Expand Down Expand Up @@ -1973,7 +1981,7 @@ mod tests {

assert_eq!(processed_transactions_count, 0,);

retryable_txs.sort();
retryable_txs.sort_unstable();
let expected: Vec<usize> = (0..transactions.len()).collect();
assert_eq!(retryable_txs, expected);
}
Expand Down
7 changes: 5 additions & 2 deletions core/src/broadcast_stage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! A stage to broadcast data from a leader node to validators
#![allow(clippy::rc_buffer)]
use self::{
broadcast_fake_shreds_run::BroadcastFakeShredsRun, broadcast_metrics::*,
fail_entry_verification_broadcast_run::FailEntryVerificationBroadcastRun,
Expand Down Expand Up @@ -518,8 +519,10 @@ pub mod test {

#[test]
fn test_num_live_peers() {
let mut ci = ContactInfo::default();
ci.wallclock = std::u64::MAX;
let mut ci = ContactInfo {
wallclock: std::u64::MAX,
..ContactInfo::default()
};
assert_eq!(num_live_peers(&[ci.clone()]), 1);
ci.wallclock = timestamp() - 1;
assert_eq!(num_live_peers(&[ci.clone()]), 2);
Expand Down
3 changes: 1 addition & 2 deletions core/src/broadcast_stage/broadcast_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ mod test {
}

assert!(slot_broadcast_stats.lock().unwrap().0.get(&slot).is_none());
let (returned_count, returned_slot, returned_instant) = receiver.recv().unwrap();
let (returned_count, returned_slot, _returned_instant) = receiver.recv().unwrap();
assert_eq!(returned_count, num_threads);
assert_eq!(returned_slot, slot);
assert_eq!(returned_instant, returned_instant);
}
}
}
8 changes: 5 additions & 3 deletions core/src/broadcast_stage/standard_broadcast_run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::rc_buffer)]

use super::{
broadcast_utils::{self, ReceiveResults},
*,
Expand Down Expand Up @@ -284,7 +286,7 @@ impl StandardBroadcastRun {
blockstore: &Arc<Blockstore>,
shreds: Arc<Vec<Shred>>,
broadcast_shred_batch_info: Option<BroadcastShredBatchInfo>,
) -> Result<()> {
) {
// Insert shreds into blockstore
let insert_shreds_start = Instant::now();
// The first shred is inserted synchronously
Expand All @@ -302,7 +304,6 @@ impl StandardBroadcastRun {
num_shreds: shreds.len(),
};
self.update_insertion_metrics(&new_insert_shreds_stats, &broadcast_shred_batch_info);
Ok(())
}

fn update_insertion_metrics(
Expand Down Expand Up @@ -438,7 +439,8 @@ impl BroadcastRun for StandardBroadcastRun {
blockstore: &Arc<Blockstore>,
) -> Result<()> {
let (shreds, slot_start_ts) = receiver.lock().unwrap().recv()?;
self.insert(blockstore, shreds, slot_start_ts)
self.insert(blockstore, shreds, slot_start_ts);
Ok(())
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl ClusterInfo {
))
})
.collect();
current_slots.sort();
current_slots.sort_unstable();
let min_slot: Slot = current_slots
.iter()
.map(|((_, s), _)| *s)
Expand Down Expand Up @@ -4139,8 +4139,10 @@ mod tests {

#[test]
fn test_protocol_sanitize() {
let mut pd = PruneData::default();
pd.wallclock = MAX_WALLCLOCK;
let pd = PruneData {
wallclock: MAX_WALLCLOCK,
..PruneData::default()
};
let msg = Protocol::PruneMessage(Pubkey::default(), pd);
assert_eq!(msg.sanitize(), Err(SanitizeError::ValueOutOfBounds));
}
Expand Down
Loading

0 comments on commit 7143aaa

Please sign in to comment.