From 0781fe1b4f70a9cdbfb09f5c7de1ebc567d5da5c Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Wed, 19 May 2021 09:31:47 -0500 Subject: [PATCH] Upgrade Rust to 1.52.0 (#17096) * Upgrade Rust to 1.52.0 update nightly_version to newly pushed docker image fix clippy lint errors 1.52 comes with grcov 0.8.0, include this version to script * upgrade to Rust 1.52.1 * disabling Serum from downstream projects until it is upgraded to Rust 1.52.1 --- Cargo.lock | 1 - ci/docker-rust-nightly/Dockerfile | 2 +- ci/docker-rust/Dockerfile | 2 +- ci/rust-version.sh | 4 +- cli/src/checks.rs | 15 +- cli/src/lib.rs | 1 - cli/tests/program.rs | 22 +-- client/src/rpc_client.rs | 2 +- core/src/banking_stage.rs | 6 +- core/src/cluster_info.rs | 12 +- core/src/consensus.rs | 2 + core/src/crds_gossip_pull.rs | 12 +- core/src/epoch_slots.rs | 4 +- core/src/gossip_service.rs | 20 +-- core/src/heaviest_subtree_fork_choice.rs | 6 +- core/src/lib.rs | 2 +- core/src/poh_recorder.rs | 50 ++----- core/src/retransmit_stage.rs | 4 +- core/src/sigverify_shreds.rs | 4 +- core/src/verified_vote_packets.rs | 2 +- core/src/window_service.rs | 103 ++++++++----- core/tests/rpc.rs | 2 +- frozen-abi/macro/Cargo.toml | 1 - frozen-abi/macro/src/lib.rs | 39 ----- ledger/src/blockstore.rs | 37 ++--- ledger/src/blockstore/blockstore_purge.rs | 2 +- ledger/src/entry.rs | 39 ++--- ledger/src/lib.rs | 2 +- ledger/src/poh.rs | 138 ++++++++---------- local-cluster/src/cluster_tests.rs | 2 +- perf/src/cuda_runtime.rs | 2 +- perf/src/recycler.rs | 1 + perf/src/sigverify.rs | 4 +- programs/bpf/Cargo.lock | 1 - programs/bpf_loader/src/syscalls.rs | 2 + programs/stake/src/lib.rs | 2 +- programs/stake/src/stake_state.rs | 121 +++++++-------- programs/vote/src/lib.rs | 2 +- .../optimistically_confirmed_bank_tracker.rs | 8 +- rpc/src/rpc_subscriptions.rs | 18 +-- runtime/src/accounts.rs | 1 + runtime/src/accounts_db.rs | 5 +- runtime/src/append_vec.rs | 4 +- runtime/src/bank.rs | 10 +- runtime/src/lib.rs | 2 +- runtime/src/message_processor.rs | 14 +- scripts/build-downstream-projects.sh | 2 +- scripts/coverage.sh | 2 +- sdk/program/src/message.rs | 12 +- sdk/program/src/sysvar/recent_blockhashes.rs | 5 +- sdk/src/account.rs | 8 +- sdk/src/packet.rs | 1 + tokens/src/commands.rs | 1 + version/src/lib.rs | 2 +- 54 files changed, 345 insertions(+), 423 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f9151a40f..2ed71fd23f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4519,7 +4519,6 @@ dependencies = [ name = "solana-frozen-abi-macro" version = "1.7.0" dependencies = [ - "lazy_static", "proc-macro2 1.0.24", "quote 1.0.6", "rustc_version", diff --git a/ci/docker-rust-nightly/Dockerfile b/ci/docker-rust-nightly/Dockerfile index 4cf08b7cba..8d3f41255a 100644 --- a/ci/docker-rust-nightly/Dockerfile +++ b/ci/docker-rust-nightly/Dockerfile @@ -1,4 +1,4 @@ -FROM solanalabs/rust:1.51.0 +FROM solanalabs/rust:1.52.1 ARG date RUN set -x \ diff --git a/ci/docker-rust/Dockerfile b/ci/docker-rust/Dockerfile index bad2bd7150..950698e07d 100644 --- a/ci/docker-rust/Dockerfile +++ b/ci/docker-rust/Dockerfile @@ -1,6 +1,6 @@ # Note: when the rust version is changed also modify # ci/rust-version.sh to pick up the new image tag -FROM rust:1.51.0 +FROM rust:1.52.1 # Add Google Protocol Buffers for Libra's metrics library. ENV PROTOC_VERSION 3.8.0 diff --git a/ci/rust-version.sh b/ci/rust-version.sh index b8719f2800..5d0cdc5bd0 100644 --- a/ci/rust-version.sh +++ b/ci/rust-version.sh @@ -18,13 +18,13 @@ if [[ -n $RUST_STABLE_VERSION ]]; then stable_version="$RUST_STABLE_VERSION" else - stable_version=1.51.0 + stable_version=1.52.1 fi if [[ -n $RUST_NIGHTLY_VERSION ]]; then nightly_version="$RUST_NIGHTLY_VERSION" else - nightly_version=2021-04-18 + nightly_version=2021-05-18 fi diff --git a/cli/src/checks.rs b/cli/src/checks.rs index 3a3898ee86..92a365c76d 100644 --- a/cli/src/checks.rs +++ b/cli/src/checks.rs @@ -231,18 +231,9 @@ mod tests { mocks.insert(RpcRequest::GetBalance, account_balance_response); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - assert_eq!( - check_account_for_balance(&rpc_client, &pubkey, 1).unwrap(), - true - ); - assert_eq!( - check_account_for_balance(&rpc_client, &pubkey, account_balance).unwrap(), - true - ); - assert_eq!( - check_account_for_balance(&rpc_client, &pubkey, account_balance + 1).unwrap(), - false - ); + assert!(check_account_for_balance(&rpc_client, &pubkey, 1).unwrap()); + assert!(check_account_for_balance(&rpc_client, &pubkey, account_balance).unwrap()); + assert!(!check_account_for_balance(&rpc_client, &pubkey, account_balance + 1).unwrap()); } #[test] diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 55d0b947f0..21596aa94c 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -10,7 +10,6 @@ macro_rules! ACCOUNT_STRING { }; } -#[macro_use] macro_rules! pubkey { ($arg:expr, $help:expr) => { $arg.takes_value(true) diff --git a/cli/tests/program.rs b/cli/tests/program.rs index 15d7e6ae83..5a83d0ea24 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -72,7 +72,7 @@ fn test_cli_program_deploy_non_upgradeable() { let account0 = rpc_client.get_account(&program_id).unwrap(); assert_eq!(account0.lamports, minimum_balance_for_rent_exemption); assert_eq!(account0.owner, bpf_loader::id()); - assert_eq!(account0.executable, true); + assert!(account0.executable); let mut file = File::open(pathbuf.to_str().unwrap().to_string()).unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); @@ -93,7 +93,7 @@ fn test_cli_program_deploy_non_upgradeable() { .unwrap(); assert_eq!(account1.lamports, minimum_balance_for_rent_exemption); assert_eq!(account1.owner, bpf_loader::id()); - assert_eq!(account1.executable, true); + assert!(account1.executable); assert_eq!(account1.data, account0.data); // Attempt to redeploy to the same address @@ -129,7 +129,7 @@ fn test_cli_program_deploy_non_upgradeable() { .unwrap(); assert_eq!(account2.lamports, 2 * minimum_balance_for_rent_exemption); assert_eq!(account2.owner, bpf_loader::id()); - assert_eq!(account2.executable, true); + assert!(account2.executable); assert_eq!(account2.data, account0.data); } @@ -289,7 +289,7 @@ fn test_cli_program_deploy_with_authority() { let program_account = rpc_client.get_account(&program_keypair.pubkey()).unwrap(); assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(program_account.executable, true); + assert!(program_account.executable); let (programdata_pubkey, _) = Pubkey::find_program_address( &[program_keypair.pubkey().as_ref()], &bpf_loader_upgradeable::id(), @@ -300,7 +300,7 @@ fn test_cli_program_deploy_with_authority() { minimum_balance_for_programdata ); assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(programdata_account.executable, false); + assert!(!programdata_account.executable); assert_eq!( programdata_account.data[UpgradeableLoaderState::programdata_data_offset().unwrap()..], program_data[..] @@ -332,7 +332,7 @@ fn test_cli_program_deploy_with_authority() { let program_account = rpc_client.get_account(&program_pubkey).unwrap(); assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(program_account.executable, true); + assert!(program_account.executable); let (programdata_pubkey, _) = Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap(); @@ -341,7 +341,7 @@ fn test_cli_program_deploy_with_authority() { minimum_balance_for_programdata ); assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(programdata_account.executable, false); + assert!(!programdata_account.executable); assert_eq!( programdata_account.data[UpgradeableLoaderState::programdata_data_offset().unwrap()..], program_data[..] @@ -364,7 +364,7 @@ fn test_cli_program_deploy_with_authority() { let program_account = rpc_client.get_account(&program_pubkey).unwrap(); assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(program_account.executable, true); + assert!(program_account.executable); let (programdata_pubkey, _) = Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap(); @@ -373,7 +373,7 @@ fn test_cli_program_deploy_with_authority() { minimum_balance_for_programdata ); assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(programdata_account.executable, false); + assert!(!programdata_account.executable); assert_eq!( programdata_account.data[UpgradeableLoaderState::programdata_data_offset().unwrap()..], program_data[..] @@ -418,7 +418,7 @@ fn test_cli_program_deploy_with_authority() { let program_account = rpc_client.get_account(&program_pubkey).unwrap(); assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(program_account.executable, true); + assert!(program_account.executable); let (programdata_pubkey, _) = Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap(); @@ -427,7 +427,7 @@ fn test_cli_program_deploy_with_authority() { minimum_balance_for_programdata ); assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id()); - assert_eq!(programdata_account.executable, false); + assert!(!programdata_account.executable); assert_eq!( programdata_account.data[UpgradeableLoaderState::programdata_data_offset().unwrap()..], program_data[..] diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 19585633a6..5f1d92740b 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -2034,7 +2034,7 @@ mod tests { // Send erroneous parameter let blockhash: ClientResult = rpc_client.send(RpcRequest::GetRecentBlockhash, json!(["parameter"])); - assert_eq!(blockhash.is_err(), true); + assert!(blockhash.is_err()); } #[test] diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 518f668f15..6ef1ea4f10 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -1547,7 +1547,7 @@ mod tests { .collect(); trace!("done"); assert_eq!(entries.len(), genesis_config.ticks_per_slot as usize); - assert_eq!(entries.verify(&start_hash), true); + assert!(entries.verify(&start_hash)); assert_eq!(entries[entries.len() - 1].hash, bank.last_blockhash()); banking_stage.join().unwrap(); } @@ -1656,7 +1656,7 @@ mod tests { .map(|(_bank, (entry, _tick_height))| entry) .collect(); - assert_eq!(entries.verify(&blockhash), true); + assert!(entries.verify(&blockhash)); if !entries.is_empty() { blockhash = entries.last().unwrap().hash; for entry in entries { @@ -2124,7 +2124,7 @@ mod tests { } trace!("done ticking"); - assert_eq!(done, true); + assert!(done); let transactions = vec![system_transaction::transfer( &mint_keypair, diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 49660f1432..5393ef6651 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -2369,6 +2369,7 @@ impl ClusterInfo { } } + #[allow(clippy::needless_collect)] fn handle_batch_push_messages( &self, messages: Vec<(Pubkey, Vec)>, @@ -3229,6 +3230,7 @@ mod tests { } #[test] + #[allow(clippy::needless_collect)] fn test_handle_ping_messages() { let mut rng = rand::thread_rng(); let this_node = Arc::new(Keypair::new()); @@ -3583,7 +3585,7 @@ mod tests { .unwrap() .new_push_messages(cluster_info.drain_push_queue(), timestamp()); // there should be some pushes ready - assert_eq!(push_messages.is_empty(), false); + assert!(!push_messages.is_empty()); push_messages .values() .for_each(|v| v.par_iter().for_each(|v| assert!(v.verify()))); @@ -3934,6 +3936,7 @@ mod tests { } #[test] + #[allow(clippy::needless_collect)] fn test_split_messages_packet_size() { // Test that if a value is smaller than payload size but too large to be wrapped in a vec // that it is still dropped @@ -3967,9 +3970,10 @@ mod tests { let expected_len = (NUM_VALUES + num_values_per_payload - 1) / num_values_per_payload; let msgs = vec![value; NUM_VALUES as usize]; - let split: Vec<_> = - ClusterInfo::split_gossip_messages(PUSH_MESSAGE_MAX_PAYLOAD_SIZE, msgs).collect(); - assert!(split.len() as u64 <= expected_len); + assert!( + ClusterInfo::split_gossip_messages(PUSH_MESSAGE_MAX_PAYLOAD_SIZE, msgs).count() as u64 + <= expected_len + ); } #[test] diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 6f11649fc8..beda8f9905 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -91,6 +91,8 @@ pub type Stake = u64; pub type VotedStakes = HashMap; pub type PubkeyVotes = Vec<(Pubkey, Slot)>; +// lint warning "bank_weight is never read" +#[allow(dead_code)] pub(crate) struct ComputedBankState { pub voted_stakes: VotedStakes, pub total_stake: Stake, diff --git a/core/src/crds_gossip_pull.rs b/core/src/crds_gossip_pull.rs index d74eceaada..64d4dbc9c7 100644 --- a/core/src/crds_gossip_pull.rs +++ b/core/src/crds_gossip_pull.rs @@ -1476,11 +1476,13 @@ mod test { } } fn run_test_mask(mask_bits: u32) { - let masks: Vec<_> = (0..2u64.pow(mask_bits)) - .map(|seed| CrdsFilter::compute_mask(seed, mask_bits)) - .dedup() - .collect(); - assert_eq!(masks.len(), 2u64.pow(mask_bits) as usize) + assert_eq!( + (0..2u64.pow(mask_bits)) + .map(|seed| CrdsFilter::compute_mask(seed, mask_bits)) + .dedup() + .count(), + 2u64.pow(mask_bits) as usize + ) } #[test] diff --git a/core/src/epoch_slots.rs b/core/src/epoch_slots.rs index d4ce59a640..e3061e5e90 100644 --- a/core/src/epoch_slots.rs +++ b/core/src/epoch_slots.rs @@ -382,7 +382,7 @@ mod tests { assert_eq!(slots.to_slots(1), vec![1, 2, 10]); assert_eq!(slots.to_slots(2), vec![2, 10]); assert_eq!(slots.to_slots(3), vec![10]); - assert_eq!(slots.to_slots(11).is_empty(), true); + assert!(slots.to_slots(11).is_empty()); } #[test] fn test_epoch_slots_compressed() { @@ -452,7 +452,7 @@ mod tests { assert_eq!(slots.wallclock, 1); assert_eq!(slots.to_slots(0), range); assert_eq!(slots.to_slots(4999), vec![4999]); - assert_eq!(slots.to_slots(5000).is_empty(), true); + assert!(slots.to_slots(5000).is_empty()); } #[test] fn test_epoch_slots_fill_sparce_range() { diff --git a/core/src/gossip_service.rs b/core/src/gossip_service.rs index d73b24dca9..1d28cda0b4 100644 --- a/core/src/gossip_service.rs +++ b/core/src/gossip_service.rs @@ -342,19 +342,19 @@ mod tests { let spy_ref = Arc::new(cluster_info); let (met_criteria, secs, _, tvu_peers) = spy(spy_ref.clone(), None, Some(1), None, None); - assert_eq!(met_criteria, false); + assert!(!met_criteria); assert_eq!(secs, 1); assert_eq!(tvu_peers, spy_ref.tvu_peers()); // Find num_nodes let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), None, None, None); - assert_eq!(met_criteria, true); + assert!(met_criteria); let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(2), None, None, None); - assert_eq!(met_criteria, true); + assert!(met_criteria); // Find specific node by pubkey let (met_criteria, _, _, _) = spy(spy_ref.clone(), None, None, Some(peer0), None); - assert_eq!(met_criteria, true); + assert!(met_criteria); let (met_criteria, _, _, _) = spy( spy_ref.clone(), None, @@ -362,13 +362,13 @@ mod tests { Some(solana_sdk::pubkey::new_rand()), None, ); - assert_eq!(met_criteria, false); + assert!(!met_criteria); // Find num_nodes *and* specific node by pubkey let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), None, Some(peer0), None); - assert_eq!(met_criteria, true); + assert!(met_criteria); let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(3), Some(0), Some(peer0), None); - assert_eq!(met_criteria, false); + assert!(!met_criteria); let (met_criteria, _, _, _) = spy( spy_ref.clone(), Some(1), @@ -376,12 +376,12 @@ mod tests { Some(solana_sdk::pubkey::new_rand()), None, ); - assert_eq!(met_criteria, false); + assert!(!met_criteria); // Find specific node by gossip address let (met_criteria, _, _, _) = spy(spy_ref.clone(), None, None, None, Some(&peer0_info.gossip)); - assert_eq!(met_criteria, true); + assert!(met_criteria); let (met_criteria, _, _, _) = spy( spy_ref, @@ -390,6 +390,6 @@ mod tests { None, Some(&"1.1.1.1:1234".parse().unwrap()), ); - assert_eq!(met_criteria, false); + assert!(!met_criteria); } } diff --git a/core/src/heaviest_subtree_fork_choice.rs b/core/src/heaviest_subtree_fork_choice.rs index 538ed432c5..fb1f10eac0 100644 --- a/core/src/heaviest_subtree_fork_choice.rs +++ b/core/src/heaviest_subtree_fork_choice.rs @@ -2685,7 +2685,7 @@ mod test { let mut tower = Tower::new_for_tests(10, 0.9); tower.record_vote(1, Hash::default()); - assert_eq!(tower.is_stray_last_vote(), false); + assert!(!tower.is_stray_last_vote()); assert_eq!( heaviest_subtree_fork_choice.heaviest_slot_on_same_voted_fork(&tower), Some((2, Hash::default())) @@ -2700,7 +2700,7 @@ mod test { .adjust_lockouts_after_replay(0, &slot_history) .unwrap(); - assert_eq!(tower.is_stray_last_vote(), true); + assert!(tower.is_stray_last_vote()); assert_eq!( heaviest_subtree_fork_choice.heaviest_slot_on_same_voted_fork(&tower), Some((2, Hash::default())) @@ -2712,7 +2712,7 @@ mod test { .adjust_lockouts_after_replay(0, &slot_history) .unwrap(); - assert_eq!(tower.is_stray_last_vote(), true); + assert!(tower.is_stray_last_vote()); assert_eq!( heaviest_subtree_fork_choice.heaviest_slot_on_same_voted_fork(&tower), None diff --git a/core/src/lib.rs b/core/src/lib.rs index 8ecc953a30..d418689864 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![allow(clippy::integer_arithmetic)] //! The `solana` library implements the Solana high-performance blockchain architecture. //! It includes a full Rust implementation of the architecture (see diff --git a/core/src/poh_recorder.rs b/core/src/poh_recorder.rs index b6fdac5fe0..6753049a1a 100644 --- a/core/src/poh_recorder.rs +++ b/core/src/poh_recorder.rs @@ -1413,7 +1413,7 @@ mod tests { let bootstrap_validator_id = leader_schedule_cache.slot_leader_at(0, None).unwrap(); - assert_eq!(poh_recorder.reached_leader_tick(0), true); + assert!(poh_recorder.reached_leader_tick(0)); let grace_ticks = bank.ticks_per_slot() * MAX_GRACE_SLOTS; let new_tick_height = NUM_CONSECUTIVE_LEADER_SLOTS * bank.ticks_per_slot(); @@ -1475,11 +1475,11 @@ mod tests { ); // Test that with no next leader slot, we don't reach the leader slot - assert_eq!(poh_recorder.reached_leader_slot().0, false); + assert!(!poh_recorder.reached_leader_slot().0); // Test that with no next leader slot in reset(), we don't reach the leader slot poh_recorder.reset(bank.last_blockhash(), 0, None); - assert_eq!(poh_recorder.reached_leader_slot().0, false); + assert!(!poh_recorder.reached_leader_slot().0); // Provide a leader slot one slot down poh_recorder.reset(bank.last_blockhash(), 0, Some((2, 2))); @@ -1507,13 +1507,13 @@ mod tests { .unwrap(); // Test that we don't reach the leader slot because of grace ticks - assert_eq!(poh_recorder.reached_leader_slot().0, false); + assert!(!poh_recorder.reached_leader_slot().0); // reset poh now. we should immediately be leader poh_recorder.reset(bank.last_blockhash(), 1, Some((2, 2))); let (reached_leader_slot, grace_ticks, leader_slot, ..) = poh_recorder.reached_leader_slot(); - assert_eq!(reached_leader_slot, true); + assert!(reached_leader_slot); assert_eq!(grace_ticks, 0); assert_eq!(leader_slot, 2); @@ -1527,7 +1527,7 @@ mod tests { } // We are not the leader yet, as expected - assert_eq!(poh_recorder.reached_leader_slot().0, false); + assert!(!poh_recorder.reached_leader_slot().0); // Send the grace ticks for _ in 0..bank.ticks_per_slot() / GRACE_TICKS_FACTOR { @@ -1537,7 +1537,7 @@ mod tests { // We should be the leader now let (reached_leader_slot, grace_ticks, leader_slot, ..) = poh_recorder.reached_leader_slot(); - assert_eq!(reached_leader_slot, true); + assert!(reached_leader_slot); assert_eq!(grace_ticks, bank.ticks_per_slot() / GRACE_TICKS_FACTOR); assert_eq!(leader_slot, 3); @@ -1551,13 +1551,13 @@ mod tests { } // We are not the leader yet, as expected - assert_eq!(poh_recorder.reached_leader_slot().0, false); + assert!(!poh_recorder.reached_leader_slot().0); poh_recorder.reset(bank.last_blockhash(), 3, Some((4, 4))); // without sending more ticks, we should be leader now let (reached_leader_slot, grace_ticks, leader_slot, ..) = poh_recorder.reached_leader_slot(); - assert_eq!(reached_leader_slot, true); + assert!(reached_leader_slot); assert_eq!(grace_ticks, 0); assert_eq!(leader_slot, 4); @@ -1575,7 +1575,7 @@ mod tests { // We are overdue to lead let (reached_leader_slot, grace_ticks, leader_slot, ..) = poh_recorder.reached_leader_slot(); - assert_eq!(reached_leader_slot, true); + assert!(reached_leader_slot); assert_eq!(grace_ticks, overshoot_factor * bank.ticks_per_slot()); assert_eq!(leader_slot, 9); } @@ -1605,47 +1605,29 @@ mod tests { ); // Test that with no leader slot, we don't reach the leader tick - assert_eq!( - poh_recorder.would_be_leader(2 * bank.ticks_per_slot()), - false - ); + assert!(!poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); poh_recorder.reset(bank.last_blockhash(), 0, None); - assert_eq!( - poh_recorder.would_be_leader(2 * bank.ticks_per_slot()), - false - ); + assert!(!poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); // We reset with leader slot after 3 slots let bank_slot = bank.slot() + 3; poh_recorder.reset(bank.last_blockhash(), 0, Some((bank_slot, bank_slot))); // Test that the node won't be leader in next 2 slots - assert_eq!( - poh_recorder.would_be_leader(2 * bank.ticks_per_slot()), - false - ); + assert!(!poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); // Test that the node will be leader in next 3 slots - assert_eq!( - poh_recorder.would_be_leader(3 * bank.ticks_per_slot()), - true - ); + assert!(poh_recorder.would_be_leader(3 * bank.ticks_per_slot())); - assert_eq!( - poh_recorder.would_be_leader(2 * bank.ticks_per_slot()), - false - ); + assert!(!poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); // Move the bank up a slot (so that max_tick_height > slot 0's tick_height) let bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 1)); // If we set the working bank, the node should be leader within next 2 slots poh_recorder.set_bank(&bank); - assert_eq!( - poh_recorder.would_be_leader(2 * bank.ticks_per_slot()), - true - ); + assert!(poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); } } diff --git a/core/src/retransmit_stage.rs b/core/src/retransmit_stage.rs index 07d7075da8..f7716c2370 100644 --- a/core/src/retransmit_stage.rs +++ b/core/src/retransmit_stage.rs @@ -739,7 +739,7 @@ mod tests { let mut packets = Packets::new(vec![]); solana_streamer::packet::recv_from(&mut packets, &me_retransmit, 1).unwrap(); assert_eq!(packets.packets.len(), 1); - assert_eq!(packets.packets[0].meta.repair, false); + assert!(!packets.packets[0].meta.repair); let mut repair = packet.clone(); repair.meta.repair = true; @@ -752,7 +752,7 @@ mod tests { let mut packets = Packets::new(vec![]); solana_streamer::packet::recv_from(&mut packets, &me_retransmit, 1).unwrap(); assert_eq!(packets.packets.len(), 1); - assert_eq!(packets.packets[0].meta.repair, false); + assert!(!packets.packets[0].meta.repair); } #[test] diff --git a/core/src/sigverify_shreds.rs b/core/src/sigverify_shreds.rs index 98ff0bd2b6..d3403d6523 100644 --- a/core/src/sigverify_shreds.rs +++ b/core/src/sigverify_shreds.rs @@ -153,7 +153,7 @@ pub mod tests { batch[0].packets[1].meta.size = shred.payload.len(); let rv = verifier.verify_batch(batch); - assert_eq!(rv[0].packets[0].meta.discard, false); - assert_eq!(rv[0].packets[1].meta.discard, true); + assert!(!rv[0].packets[0].meta.discard); + assert!(rv[0].packets[1].meta.discard); } } diff --git a/core/src/verified_vote_packets.rs b/core/src/verified_vote_packets.rs index 9136b668c7..761136e8f3 100644 --- a/core/src/verified_vote_packets.rs +++ b/core/src/verified_vote_packets.rs @@ -105,7 +105,7 @@ mod tests { // Only the nonempty packet had a timestamp greater than 1 let (new_update_version, updates) = verified_vote_packets.get_latest_votes(1); assert_eq!(new_update_version, 2); - assert_eq!(updates.packets.is_empty(), false); + assert!(!updates.packets.is_empty()); // If the given timestamp is greater than all timestamps in any update, // returned timestamp should be the same as the given timestamp, and diff --git a/core/src/window_service.rs b/core/src/window_service.rs index a407fc061e..457dc88bf1 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -671,63 +671,94 @@ mod test { let mut shreds = local_entries_to_shred(&[Entry::default()], 0, 0, &leader_keypair); // with a Bank for slot 0, shred continues - assert_eq!( - should_retransmit_and_persist(&shreds[0], Some(bank.clone()), &cache, &me_id, 0, 0), - true - ); + assert!(should_retransmit_and_persist( + &shreds[0], + Some(bank.clone()), + &cache, + &me_id, + 0, + 0 + )); // with the wrong shred_version, shred gets thrown out - assert_eq!( - should_retransmit_and_persist(&shreds[0], Some(bank.clone()), &cache, &me_id, 0, 1), - false - ); + assert!(!should_retransmit_and_persist( + &shreds[0], + Some(bank.clone()), + &cache, + &me_id, + 0, + 1 + )); // If it's a coding shred, test that slot >= root let (common, coding) = Shredder::new_coding_shred_header(5, 5, 5, 6, 6, 0); let mut coding_shred = Shred::new_empty_from_header(common, DataShredHeader::default(), coding); Shredder::sign_shred(&leader_keypair, &mut coding_shred); - assert_eq!( - should_retransmit_and_persist(&coding_shred, Some(bank.clone()), &cache, &me_id, 0, 0), - true - ); - assert_eq!( - should_retransmit_and_persist(&coding_shred, Some(bank.clone()), &cache, &me_id, 5, 0), - true - ); - assert_eq!( - should_retransmit_and_persist(&coding_shred, Some(bank.clone()), &cache, &me_id, 6, 0), - false - ); + assert!(should_retransmit_and_persist( + &coding_shred, + Some(bank.clone()), + &cache, + &me_id, + 0, + 0 + )); + assert!(should_retransmit_and_persist( + &coding_shred, + Some(bank.clone()), + &cache, + &me_id, + 5, + 0 + )); + assert!(!should_retransmit_and_persist( + &coding_shred, + Some(bank.clone()), + &cache, + &me_id, + 6, + 0 + )); // with a Bank and no idea who leader is, shred gets thrown out shreds[0].set_slot(MINIMUM_SLOTS_PER_EPOCH as u64 * 3); - assert_eq!( - should_retransmit_and_persist(&shreds[0], Some(bank.clone()), &cache, &me_id, 0, 0), - false - ); + assert!(!should_retransmit_and_persist( + &shreds[0], + Some(bank.clone()), + &cache, + &me_id, + 0, + 0 + )); // with a shred where shred.slot() == root, shred gets thrown out let slot = MINIMUM_SLOTS_PER_EPOCH as u64 * 3; let shreds = local_entries_to_shred(&[Entry::default()], slot, slot - 1, &leader_keypair); - assert_eq!( - should_retransmit_and_persist(&shreds[0], Some(bank.clone()), &cache, &me_id, slot, 0), - false - ); + assert!(!should_retransmit_and_persist( + &shreds[0], + Some(bank.clone()), + &cache, + &me_id, + slot, + 0 + )); // with a shred where shred.parent() < root, shred gets thrown out let slot = MINIMUM_SLOTS_PER_EPOCH as u64 * 3; let shreds = local_entries_to_shred(&[Entry::default()], slot + 1, slot - 1, &leader_keypair); - assert_eq!( - should_retransmit_and_persist(&shreds[0], Some(bank), &cache, &me_id, slot, 0), - false - ); + assert!(!should_retransmit_and_persist( + &shreds[0], + Some(bank), + &cache, + &me_id, + slot, + 0 + )); // if the shred came back from me, it doesn't continue, whether or not I have a bank - assert_eq!( - should_retransmit_and_persist(&shreds[0], None, &cache, &me_id, 0, 0), - false - ); + assert!(!should_retransmit_and_persist( + &shreds[0], None, &cache, &me_id, 0, 0 + )); } #[test] diff --git a/core/tests/rpc.rs b/core/tests/rpc.rs index 6258e90af9..ee8291f8d1 100644 --- a/core/tests/rpc.rs +++ b/core/tests/rpc.rs @@ -100,7 +100,7 @@ fn test_rpc_send_tx() { sleep(Duration::from_millis(500)); } - assert_eq!(confirmed_tx, true); + assert!(confirmed_tx); use solana_account_decoder::UiAccountEncoding; use solana_client::rpc_config::RpcAccountInfoConfig; diff --git a/frozen-abi/macro/Cargo.toml b/frozen-abi/macro/Cargo.toml index e6b90b1798..eaf31a2c37 100644 --- a/frozen-abi/macro/Cargo.toml +++ b/frozen-abi/macro/Cargo.toml @@ -16,7 +16,6 @@ proc-macro = true proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = ["full", "extra-traits"] } -lazy_static = "1.4.0" [build-dependencies] rustc_version = "0.2" diff --git a/frozen-abi/macro/src/lib.rs b/frozen-abi/macro/src/lib.rs index 20ef3ba885..bd285a826c 100644 --- a/frozen-abi/macro/src/lib.rs +++ b/frozen-abi/macro/src/lib.rs @@ -1,9 +1,5 @@ extern crate proc_macro; -#[cfg(RUSTC_WITH_SPECIALIZATION)] -#[macro_use] -extern crate lazy_static; - // This file littered with these essential cfgs so ensure them. #[cfg(not(any(RUSTC_WITH_SPECIALIZATION, RUSTC_WITHOUT_SPECIALIZATION)))] compile_error!("rustc_version is missing in build dependency and build.rs is not specified"); @@ -71,37 +67,6 @@ fn filter_allow_attrs(attrs: &mut Vec) { }); } -#[allow(deprecated)] -#[cfg(RUSTC_WITH_SPECIALIZATION)] -fn quote_for_specialization_detection() -> TokenStream2 { - lazy_static! { - static ref SPECIALIZATION_DETECTOR_INJECTED: std::sync::atomic::AtomicBool = - std::sync::atomic::AtomicBool::new(false); - } - - if !SPECIALIZATION_DETECTOR_INJECTED.compare_and_swap( - false, - true, - std::sync::atomic::Ordering::AcqRel, - ) { - quote! { - mod specialization_detector { - trait SpecializedTrait { - fn specialized_fn() {} - } - impl SpecializedTrait for T { - default fn specialized_fn() {} - } - impl SpecializedTrait for T { - fn specialized_fn() {} - } - } - } - } else { - quote! {} - } -} - #[cfg(RUSTC_WITH_SPECIALIZATION)] fn derive_abi_sample_enum_type(input: ItemEnum) -> TokenStream { let type_name = &input.ident; @@ -162,10 +127,8 @@ fn derive_abi_sample_enum_type(input: ItemEnum) -> TokenStream { let mut attrs = input.attrs.clone(); filter_allow_attrs(&mut attrs); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let injection = quote_for_specialization_detection(); let result = quote! { - #injection #[automatically_derived] #( #attrs )* impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause { @@ -216,10 +179,8 @@ fn derive_abi_sample_struct_type(input: ItemStruct) -> TokenStream { filter_allow_attrs(&mut attrs); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let turbofish = ty_generics.as_turbofish(); - let injection = quote_for_specialization_detection(); let result = quote! { - #injection #[automatically_derived] #( #attrs )* impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause { diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index cd9d5bae8b..3a6528ffdd 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1200,7 +1200,8 @@ impl Blockstore { just_inserted_data_shreds.insert((slot, shred_index), shred); index_meta_working_set_entry.did_insert_occur = true; slot_meta_entry.did_insert_occur = true; - if !erasure_metas.contains_key(&(slot, set_index)) { + if let std::collections::hash_map::Entry::Vacant(_) = erasure_metas.entry((slot, set_index)) + { if let Some(meta) = self .erasure_meta_cf .get((slot, set_index)) @@ -5381,17 +5382,14 @@ pub mod tests { panic!("Shred in unexpected format") } }; - assert_eq!( - blockstore.should_insert_data_shred( - &shred7, - &slot_meta, - &HashMap::new(), - &last_root, - None, - false - ), + assert!(!blockstore.should_insert_data_shred( + &shred7, + &slot_meta, + &HashMap::new(), + &last_root, + None, false - ); + )); assert!(blockstore.has_duplicate_shreds_in_slot(0)); // Insert all pending shreds @@ -5405,17 +5403,14 @@ pub mod tests { } else { panic!("Shred in unexpected format") } - assert_eq!( - blockstore.should_insert_data_shred( - &shred7, - &slot_meta, - &HashMap::new(), - &last_root, - None, - false - ), + assert!(!blockstore.should_insert_data_shred( + &shred7, + &slot_meta, + &HashMap::new(), + &last_root, + None, false - ); + )); } Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction"); } diff --git a/ledger/src/blockstore/blockstore_purge.rs b/ledger/src/blockstore/blockstore_purge.rs index bd7e41e122..4fe38a3f4f 100644 --- a/ledger/src/blockstore/blockstore_purge.rs +++ b/ledger/src/blockstore/blockstore_purge.rs @@ -115,7 +115,7 @@ impl Blockstore { .batch() .expect("Database Error: Failed to get write batch"); // delete range cf is not inclusive - let to_slot = to_slot.checked_add(1).unwrap_or(std::u64::MAX); + let to_slot = to_slot.saturating_add(1); let mut delete_range_timer = Measure::start("delete_range"); let mut columns_purged = self diff --git a/ledger/src/entry.rs b/ledger/src/entry.rs index 9697d15778..f918bb37bc 100644 --- a/ledger/src/entry.rs +++ b/ledger/src/entry.rs @@ -868,17 +868,14 @@ mod tests { solana_logger::setup(); let zero = Hash::default(); let one = hash(&zero.as_ref()); - assert_eq!(vec![][..].verify(&zero), true); // base case - assert_eq!(vec![Entry::new_tick(0, &zero)][..].verify(&zero), true); // singleton case 1 - assert_eq!(vec![Entry::new_tick(0, &zero)][..].verify(&one), false); // singleton case 2, bad - assert_eq!( - vec![next_entry(&zero, 0, vec![]); 2][..].verify(&zero), - true - ); // inductive step + assert!(vec![][..].verify(&zero)); // base case + assert!(vec![Entry::new_tick(0, &zero)][..].verify(&zero)); // singleton case 1 + assert!(!vec![Entry::new_tick(0, &zero)][..].verify(&one)); // singleton case 2, bad + assert!(vec![next_entry(&zero, 0, vec![]); 2][..].verify(&zero)); // inductive step let mut bad_ticks = vec![next_entry(&zero, 0, vec![]); 2]; bad_ticks[1].hash = one; - assert_eq!(bad_ticks.verify(&zero), false); // inductive step, bad + assert!(!bad_ticks.verify(&zero)); // inductive step, bad } #[test] @@ -887,18 +884,18 @@ mod tests { let zero = Hash::default(); let one = hash(&zero.as_ref()); let two = hash(&one.as_ref()); - assert_eq!(vec![][..].verify(&one), true); // base case - assert_eq!(vec![Entry::new_tick(1, &two)][..].verify(&one), true); // singleton case 1 - assert_eq!(vec![Entry::new_tick(1, &two)][..].verify(&two), false); // singleton case 2, bad + assert!(vec![][..].verify(&one)); // base case + assert!(vec![Entry::new_tick(1, &two)][..].verify(&one)); // singleton case 1 + assert!(!vec![Entry::new_tick(1, &two)][..].verify(&two)); // singleton case 2, bad let mut ticks = vec![next_entry(&one, 1, vec![])]; ticks.push(next_entry(&ticks.last().unwrap().hash, 1, vec![])); - assert_eq!(ticks.verify(&one), true); // inductive step + assert!(ticks.verify(&one)); // inductive step let mut bad_ticks = vec![next_entry(&one, 1, vec![])]; bad_ticks.push(next_entry(&bad_ticks.last().unwrap().hash, 1, vec![])); bad_ticks[1].hash = one; - assert_eq!(bad_ticks.verify(&one), false); // inductive step, bad + assert!(!bad_ticks.verify(&one)); // inductive step, bad } #[test] @@ -910,15 +907,9 @@ mod tests { let alice_pubkey = Keypair::new(); let tx0 = create_sample_payment(&alice_pubkey, one); let tx1 = create_sample_timestamp(&alice_pubkey, one); - assert_eq!(vec![][..].verify(&one), true); // base case - assert_eq!( - vec![next_entry(&one, 1, vec![tx0.clone()])][..].verify(&one), - true - ); // singleton case 1 - assert_eq!( - vec![next_entry(&one, 1, vec![tx0.clone()])][..].verify(&two), - false - ); // singleton case 2, bad + assert!(vec![][..].verify(&one)); // base case + assert!(vec![next_entry(&one, 1, vec![tx0.clone()])][..].verify(&one)); // singleton case 1 + assert!(!vec![next_entry(&one, 1, vec![tx0.clone()])][..].verify(&two)); // singleton case 2, bad let mut ticks = vec![next_entry(&one, 1, vec![tx0.clone()])]; ticks.push(next_entry( @@ -926,12 +917,12 @@ mod tests { 1, vec![tx1.clone()], )); - assert_eq!(ticks.verify(&one), true); // inductive step + assert!(ticks.verify(&one)); // inductive step let mut bad_ticks = vec![next_entry(&one, 1, vec![tx0])]; bad_ticks.push(next_entry(&bad_ticks.last().unwrap().hash, 1, vec![tx1])); bad_ticks[1].hash = one; - assert_eq!(bad_ticks.verify(&one), false); // inductive step, bad + assert!(!bad_ticks.verify(&one)); // inductive step, bad } #[test] diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index 603f585da3..b7542b47df 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![allow(clippy::integer_arithmetic)] #[macro_use] extern crate solana_bpf_loader_program; diff --git a/ledger/src/poh.rs b/ledger/src/poh.rs index c230afc8b9..0ade8d7a75 100644 --- a/ledger/src/poh.rs +++ b/ledger/src/poh.rs @@ -197,95 +197,77 @@ mod tests { let one_with_zero = hashv(&[&zero.as_ref(), &zero.as_ref()]); let mut poh = Poh::new(zero, None); - assert_eq!( - verify( - zero, - &[ - (poh.tick().unwrap(), None), - (poh.record(zero).unwrap(), Some(zero)), - (poh.record(zero).unwrap(), Some(zero)), - (poh.tick().unwrap(), None), - ], - ), - true - ); + assert!(verify( + zero, + &[ + (poh.tick().unwrap(), None), + (poh.record(zero).unwrap(), Some(zero)), + (poh.record(zero).unwrap(), Some(zero)), + (poh.tick().unwrap(), None), + ], + )); - assert_eq!( - verify( - zero, - &[( - PohEntry { - num_hashes: 1, - hash: one, - }, - None - )], - ), - true - ); - assert_eq!( - verify( - zero, - &[( - PohEntry { - num_hashes: 2, - hash: two, - }, - None - )] - ), - true - ); + assert!(verify( + zero, + &[( + PohEntry { + num_hashes: 1, + hash: one, + }, + None + )], + )); + assert!(verify( + zero, + &[( + PohEntry { + num_hashes: 2, + hash: two, + }, + None + )] + )); - assert_eq!( - verify( - zero, - &[( + assert!(verify( + zero, + &[( + PohEntry { + num_hashes: 1, + hash: one_with_zero, + }, + Some(zero) + )] + )); + assert!(!verify( + zero, + &[( + PohEntry { + num_hashes: 1, + hash: zero, + }, + None + )] + )); + + assert!(verify( + zero, + &[ + ( PohEntry { num_hashes: 1, hash: one_with_zero, }, Some(zero) - )] - ), - true - ); - assert_eq!( - verify( - zero, - &[( + ), + ( PohEntry { num_hashes: 1, - hash: zero, + hash: hash(&one_with_zero.as_ref()), }, None - )] - ), - false - ); - - assert_eq!( - verify( - zero, - &[ - ( - PohEntry { - num_hashes: 1, - hash: one_with_zero, - }, - Some(zero) - ), - ( - PohEntry { - num_hashes: 1, - hash: hash(&one_with_zero.as_ref()), - }, - None - ) - ] - ), - true - ); + ) + ] + )); } #[test] diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index a11b5d3912..6a9b0fe01c 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -384,7 +384,7 @@ fn get_and_verify_slot_entries( last_entry: &Hash, ) -> Vec { let entries = blockstore.get_slot_entries(slot, 0).unwrap(); - assert_eq!(entries.verify(last_entry), true); + assert!(entries.verify(last_entry)); entries } diff --git a/perf/src/cuda_runtime.rs b/perf/src/cuda_runtime.rs index 158fe8d369..3b5b054c1a 100644 --- a/perf/src/cuda_runtime.rs +++ b/perf/src/cuda_runtime.rs @@ -315,7 +315,7 @@ mod tests { assert_eq!(mem[0], 50); assert_eq!(mem[1], 10); assert_eq!(mem.len(), 2); - assert_eq!(mem.is_empty(), false); + assert!(!mem.is_empty()); let mut iter = mem.iter(); assert_eq!(*iter.next().unwrap(), 50); assert_eq!(*iter.next().unwrap(), 10); diff --git a/perf/src/recycler.rs b/perf/src/recycler.rs index 8885d8c300..1dce8e74c2 100644 --- a/perf/src/recycler.rs +++ b/perf/src/recycler.rs @@ -71,6 +71,7 @@ fn warm_recyclers() -> bool { } impl Recycler { + #[allow(clippy::needless_collect)] pub fn warmed(num: usize, size_hint: usize) -> Self { let new = Self::default(); if warm_recyclers() { diff --git a/perf/src/sigverify.rs b/perf/src/sigverify.rs index a012f1bead..a965107192 100644 --- a/perf/src/sigverify.rs +++ b/perf/src/sigverify.rs @@ -495,9 +495,9 @@ mod tests { batch.packets.push(Packet::default()); let mut batches: Vec = vec![batch]; mark_disabled(&mut batches, &[vec![0]]); - assert_eq!(batches[0].packets[0].meta.discard, true); + assert!(batches[0].packets[0].meta.discard); mark_disabled(&mut batches, &[vec![1]]); - assert_eq!(batches[0].packets[0].meta.discard, false); + assert!(!batches[0].packets[0].meta.discard); } #[test] diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index 1d96b31097..9e73d4a6c0 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -3245,7 +3245,6 @@ dependencies = [ name = "solana-frozen-abi-macro" version = "1.7.0" dependencies = [ - "lazy_static", "proc-macro2 1.0.24", "quote 1.0.6", "rustc_version", diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 039f89a1fd..456c400f27 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -2810,6 +2810,8 @@ mod tests { let bytes1 = "Gaggablaghblagh!"; let bytes2 = "flurbos"; + // lint warns field addr and len "never read" + #[allow(dead_code)] struct MockSlice { pub addr: u64, pub len: usize, diff --git a/programs/stake/src/lib.rs b/programs/stake/src/lib.rs index 23438bf8c8..f93ed51656 100644 --- a/programs/stake/src/lib.rs +++ b/programs/stake/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![allow(clippy::integer_arithmetic)] use solana_sdk::genesis_config::GenesisConfig; diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index 82eebeb4cc..81cc94e3fd 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -1881,22 +1881,16 @@ mod tests { #[test] fn test_stake_is_bootstrap() { - assert_eq!( - Delegation { - activation_epoch: std::u64::MAX, - ..Delegation::default() - } - .is_bootstrap(), - true - ); - assert_eq!( - Delegation { - activation_epoch: 0, - ..Delegation::default() - } - .is_bootstrap(), - false - ); + assert!(Delegation { + activation_epoch: std::u64::MAX, + ..Delegation::default() + } + .is_bootstrap()); + assert!(!Delegation { + activation_epoch: 0, + ..Delegation::default() + } + .is_bootstrap()); } #[test] @@ -5719,65 +5713,50 @@ mod tests { custodian, }; // neither time - assert_eq!( - lockup.is_in_force( - &Clock { - epoch: 0, - unix_timestamp: 0, - ..Clock::default() - }, - None - ), - true - ); + assert!(lockup.is_in_force( + &Clock { + epoch: 0, + unix_timestamp: 0, + ..Clock::default() + }, + None + )); // not timestamp - assert_eq!( - lockup.is_in_force( - &Clock { - epoch: 2, - unix_timestamp: 0, - ..Clock::default() - }, - None - ), - true - ); + assert!(lockup.is_in_force( + &Clock { + epoch: 2, + unix_timestamp: 0, + ..Clock::default() + }, + None + )); // not epoch - assert_eq!( - lockup.is_in_force( - &Clock { - epoch: 0, - unix_timestamp: 2, - ..Clock::default() - }, - None - ), - true - ); + assert!(lockup.is_in_force( + &Clock { + epoch: 0, + unix_timestamp: 2, + ..Clock::default() + }, + None + )); // both, no custodian - assert_eq!( - lockup.is_in_force( - &Clock { - epoch: 1, - unix_timestamp: 1, - ..Clock::default() - }, - None - ), - false - ); + assert!(!lockup.is_in_force( + &Clock { + epoch: 1, + unix_timestamp: 1, + ..Clock::default() + }, + None + )); // neither, but custodian - assert_eq!( - lockup.is_in_force( - &Clock { - epoch: 0, - unix_timestamp: 0, - ..Clock::default() - }, - Some(&custodian), - ), - false, - ); + assert!(!lockup.is_in_force( + &Clock { + epoch: 0, + unix_timestamp: 0, + ..Clock::default() + }, + Some(&custodian), + )); } #[test] diff --git a/programs/vote/src/lib.rs b/programs/vote/src/lib.rs index 57e55b52dd..ad9cf9f89c 100644 --- a/programs/vote/src/lib.rs +++ b/programs/vote/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![allow(clippy::integer_arithmetic)] pub mod authorized_voters; diff --git a/rpc/src/optimistically_confirmed_bank_tracker.rs b/rpc/src/optimistically_confirmed_bank_tracker.rs index de9278ca0a..62ab533105 100644 --- a/rpc/src/optimistically_confirmed_bank_tracker.rs +++ b/rpc/src/optimistically_confirmed_bank_tracker.rs @@ -260,7 +260,7 @@ mod tests { ); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2); assert_eq!(pending_optimistically_confirmed_banks.len(), 1); - assert_eq!(pending_optimistically_confirmed_banks.contains(&3), true); + assert!(pending_optimistically_confirmed_banks.contains(&3)); // Test bank will only be cached when frozen let bank3 = bank_forks.read().unwrap().get(3).unwrap().clone(); @@ -286,7 +286,7 @@ mod tests { ); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3); assert_eq!(pending_optimistically_confirmed_banks.len(), 1); - assert_eq!(pending_optimistically_confirmed_banks.contains(&4), true); + assert!(pending_optimistically_confirmed_banks.contains(&4)); let bank4 = bank_forks.read().unwrap().get(4).unwrap().clone(); let bank5 = Bank::new_from_parent(&bank4, &Pubkey::default(), 5); @@ -301,7 +301,7 @@ mod tests { ); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5); assert_eq!(pending_optimistically_confirmed_banks.len(), 0); - assert_eq!(pending_optimistically_confirmed_banks.contains(&4), false); + assert!(!pending_optimistically_confirmed_banks.contains(&4)); // Banks <= root do not get added to pending list, even if not frozen let bank5 = bank_forks.read().unwrap().get(5).unwrap().clone(); @@ -323,6 +323,6 @@ mod tests { ); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5); assert_eq!(pending_optimistically_confirmed_banks.len(), 0); - assert_eq!(pending_optimistically_confirmed_banks.contains(&6), false); + assert!(!pending_optimistically_confirmed_banks.contains(&6)); } } diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index 2ede992eaa..70d7e50ba3 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -1968,18 +1968,18 @@ pub(crate) mod tests { assert_eq!(subscriptions.get(&0).unwrap().len(), 2); assert_eq!(subscriptions.get(&1).unwrap().len(), 1); - assert_eq!( - remove_subscription(&mut subscriptions, &SubscriptionId::Number(0)), - true - ); + assert!(remove_subscription( + &mut subscriptions, + &SubscriptionId::Number(0) + )); assert_eq!(subscriptions.len(), num_keys as usize); assert_eq!(subscriptions.get(&0).unwrap().len(), 1); - assert_eq!( - remove_subscription(&mut subscriptions, &SubscriptionId::Number(0)), - false - ); + assert!(!remove_subscription( + &mut subscriptions, + &SubscriptionId::Number(0) + )); - assert_eq!(remove_subscription(&mut subscriptions, &extra_sub_id), true); + assert!(remove_subscription(&mut subscriptions, &extra_sub_id)); assert_eq!(subscriptions.len(), (num_keys - 1) as usize); assert!(subscriptions.get(&0).is_none()); } diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 56d122cd57..d6223ac722 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -833,6 +833,7 @@ impl Accounts { /// This function will prevent multiple threads from modifying the same account state at the /// same time #[must_use] + #[allow(clippy::needless_collect)] pub fn lock_accounts<'a>( &self, txs: impl Iterator, diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 68dde3af02..e368208fe9 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -3203,6 +3203,7 @@ impl AccountsDb { } } + #[allow(clippy::needless_collect)] fn purge_slots(&self, slots: &HashSet) { // `add_root()` should be called first let mut safety_checks_elapsed = Measure::start("safety_checks_elapsed"); @@ -6502,7 +6503,7 @@ pub mod tests { let mut pubkeys: Vec = vec![]; create_account(&accounts, &mut pubkeys, 0, 100, 0, 0); update_accounts(&accounts, &pubkeys, 0, 99); - assert_eq!(check_storage(&accounts, 0, 100), true); + assert!(check_storage(&accounts, 0, 100)); } #[test] @@ -7100,7 +7101,7 @@ pub mod tests { // do some updates to those accounts and re-check modify_accounts(&accounts, &pubkeys, 0, 100, 2); - assert_eq!(check_storage(&accounts, 0, 100), true); + assert!(check_storage(&accounts, 0, 100)); check_accounts(&accounts, &pubkeys, 0, 100, 2); accounts.get_accounts_delta_hash(0); accounts.add_root(0); diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index ae18f94a5e..fe38721fd6 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -883,7 +883,7 @@ pub mod tests { let executable_bool: &bool = &account.account_meta.executable; // Depending on use, *executable_bool can be truthy or falsy due to direct memory manipulation // assert_eq! thinks *executable_bool is equal to false but the if condition thinks it's not, contradictorily. - assert_eq!(*executable_bool, false); + assert!(!*executable_bool); const FALSE: bool = false; // keep clippy happy if *executable_bool == FALSE { panic!("This didn't occur if this test passed."); @@ -894,7 +894,7 @@ pub mod tests { // we can NOT observe crafted value by value { let executable_bool: bool = account.account_meta.executable; - assert_eq!(executable_bool, false); + assert!(!executable_bool); assert_eq!(account.get_executable_byte(), 0); // Wow, not crafted_executable! } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 2bc902ccdb..90317eedd5 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -8777,15 +8777,15 @@ pub(crate) mod tests { let tx_transfer_mint_to_1 = system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_config.hash()); assert_eq!(bank.process_transaction(&tx_transfer_mint_to_1), Ok(())); - assert_eq!(bank.is_delta.load(Relaxed), true); + assert!(bank.is_delta.load(Relaxed)); let bank1 = new_from_parent(&bank); let hash1 = bank1.hash_internal_state(); - assert_eq!(bank1.is_delta.load(Relaxed), false); + assert!(!bank1.is_delta.load(Relaxed)); assert_ne!(hash1, bank.hash()); // ticks don't make a bank into a delta or change its state unless a block boundary is crossed bank1.register_tick(&Hash::default()); - assert_eq!(bank1.is_delta.load(Relaxed), false); + assert!(!bank1.is_delta.load(Relaxed)); assert_eq!(bank1.hash_internal_state(), hash1); } @@ -8796,13 +8796,13 @@ pub(crate) mod tests { let key1 = Keypair::new(); // The zeroth bank is empty becasue there are no transactions - assert_eq!(bank0.is_empty(), true); + assert!(bank0.is_empty()); // Set is_delta to true, bank is no longer empty let tx_transfer_mint_to_1 = system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_config.hash()); assert_eq!(bank0.process_transaction(&tx_transfer_mint_to_1), Ok(())); - assert_eq!(bank0.is_empty(), false); + assert!(!bank0.is_empty()); } #[test] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6cbc020c9a..825075b0bd 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![allow(clippy::integer_arithmetic)] pub mod accounts; pub mod accounts_background_service; diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 1027befc77..07dcfd1ddb 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -1389,22 +1389,22 @@ mod tests { fn test_is_zeroed() { const ZEROS_LEN: usize = 1024; let mut buf = [0; ZEROS_LEN]; - assert_eq!(PreAccount::is_zeroed(&buf), true); + assert!(PreAccount::is_zeroed(&buf)); buf[0] = 1; - assert_eq!(PreAccount::is_zeroed(&buf), false); + assert!(!PreAccount::is_zeroed(&buf)); let mut buf = [0; ZEROS_LEN - 1]; - assert_eq!(PreAccount::is_zeroed(&buf), true); + assert!(PreAccount::is_zeroed(&buf)); buf[0] = 1; - assert_eq!(PreAccount::is_zeroed(&buf), false); + assert!(!PreAccount::is_zeroed(&buf)); let mut buf = [0; ZEROS_LEN + 1]; - assert_eq!(PreAccount::is_zeroed(&buf), true); + assert!(PreAccount::is_zeroed(&buf)); buf[0] = 1; - assert_eq!(PreAccount::is_zeroed(&buf), false); + assert!(!PreAccount::is_zeroed(&buf)); let buf = vec![]; - assert_eq!(PreAccount::is_zeroed(&buf), true); + assert!(PreAccount::is_zeroed(&buf)); } #[test] diff --git a/scripts/build-downstream-projects.sh b/scripts/build-downstream-projects.sh index f3a4117b6a..f8218c02d0 100755 --- a/scripts/build-downstream-projects.sh +++ b/scripts/build-downstream-projects.sh @@ -101,4 +101,4 @@ EOF _ example_helloworld _ spl -_ serum_dex +# _ serum_dex diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 3fd6a13890..3b241041b8 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -10,7 +10,7 @@ if ! command -v grcov; then exit 1 fi -if [[ ! "$(grcov --version)" =~ 0.[67].1 ]]; then +if [[ ! "$(grcov --version)" =~ 0.[678].[01] ]]; then echo Error: Required grcov version not installed echo "Installed version: $(grcov --version)" diff --git a/sdk/program/src/message.rs b/sdk/program/src/message.rs index 853ac9229b..98728dc7d9 100644 --- a/sdk/program/src/message.rs +++ b/sdk/program/src/message.rs @@ -865,12 +865,12 @@ mod tests { instructions: vec![], }; let demote_sysvar_write_locks = true; - assert_eq!(message.is_writable(0, demote_sysvar_write_locks), true); - assert_eq!(message.is_writable(1, demote_sysvar_write_locks), false); - assert_eq!(message.is_writable(2, demote_sysvar_write_locks), false); - assert_eq!(message.is_writable(3, demote_sysvar_write_locks), true); - assert_eq!(message.is_writable(4, demote_sysvar_write_locks), true); - assert_eq!(message.is_writable(5, demote_sysvar_write_locks), false); + assert!(message.is_writable(0, demote_sysvar_write_locks)); + assert!(!message.is_writable(1, demote_sysvar_write_locks)); + assert!(!message.is_writable(2, demote_sysvar_write_locks)); + assert!(message.is_writable(3, demote_sysvar_write_locks)); + assert!(message.is_writable(4, demote_sysvar_write_locks)); + assert!(!message.is_writable(5, demote_sysvar_write_locks)); } #[test] diff --git a/sdk/program/src/sysvar/recent_blockhashes.rs b/sdk/program/src/sysvar/recent_blockhashes.rs index f3b1649ef9..93fee5e4dc 100644 --- a/sdk/program/src/sysvar/recent_blockhashes.rs +++ b/sdk/program/src/sysvar/recent_blockhashes.rs @@ -133,11 +133,10 @@ pub fn create_test_recent_blockhashes(start: usize) -> RecentBlockhashes { ) }) .collect(); - let bhq: Vec<_> = blocks + blocks .iter() .map(|(i, hash, fee_calc)| IterItem(*i, hash, fee_calc)) - .collect(); - bhq.into_iter().collect() + .collect() } #[cfg(test)] diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 195ff71bc5..4d6d397e1f 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -700,8 +700,8 @@ pub mod tests { assert_eq!(account.data().len(), 2); assert_eq!(account.owner, key); assert_eq!(account.owner(), &key); - assert_eq!(account.executable, true); - assert_eq!(account.executable(), true); + assert!(account.executable); + assert!(account.executable()); assert_eq!(account.rent_epoch, 4); assert_eq!(account.rent_epoch(), 4); let account = account2; @@ -711,8 +711,8 @@ pub mod tests { assert_eq!(account.data().len(), 2); assert_eq!(account.owner, key); assert_eq!(account.owner(), &key); - assert_eq!(account.executable, true); - assert_eq!(account.executable(), true); + assert!(account.executable); + assert!(account.executable()); assert_eq!(account.rent_epoch, 4); assert_eq!(account.rent_epoch(), 4); } diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs index d09601b7f8..4366217798 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -72,6 +72,7 @@ impl fmt::Debug for Packet { } } +#[allow(clippy::uninit_assumed_init)] impl Default for Packet { fn default() -> Packet { Packet { diff --git a/tokens/src/commands.rs b/tokens/src/commands.rs index 340c530cfa..29e83b662a 100644 --- a/tokens/src/commands.rs +++ b/tokens/src/commands.rs @@ -423,6 +423,7 @@ fn distribute_allocations( Ok(()) } +#[allow(clippy::needless_collect)] fn read_allocations( input_csv: &str, transfer_amount: Option, diff --git a/version/src/lib.rs b/version/src/lib.rs index 351c765dd4..85afcd95c4 100644 --- a/version/src/lib.rs +++ b/version/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))] +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] extern crate serde_derive; use serde_derive::{Deserialize, Serialize};