Skip to content

Commit

Permalink
clippy for rust 1.65.0 (#28765)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Nov 9, 2022
1 parent df81cd1 commit d1ba421
Show file tree
Hide file tree
Showing 91 changed files with 232 additions and 253 deletions.
4 changes: 2 additions & 2 deletions account-decoder/src/parse_bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn parse_bpf_upgradeable_loader(
BpfUpgradeableLoaderAccountType::Buffer(UiBuffer {
authority: authority_address.map(|pubkey| pubkey.to_string()),
data: UiAccountData::Binary(
base64::encode(&data[offset as usize..]),
base64::encode(&data[offset..]),
UiAccountEncoding::Base64,
),
})
Expand All @@ -51,7 +51,7 @@ pub fn parse_bpf_upgradeable_loader(
slot,
authority: upgrade_authority_address.map(|pubkey| pubkey.to_string()),
data: UiAccountData::Binary(
base64::encode(&data[offset as usize..]),
base64::encode(&data[offset..]),
UiAccountEncoding::Base64,
),
})
Expand Down
4 changes: 2 additions & 2 deletions account-decoder/src/parse_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl UiTokenAmount {
pub fn real_number_string(&self) -> String {
real_number_string(
u64::from_str(&self.amount).unwrap_or_default(),
self.decimals as u8,
self.decimals,
)
}

Expand All @@ -242,7 +242,7 @@ impl UiTokenAmount {
} else {
real_number_string_trimmed(
u64::from_str(&self.amount).unwrap_or_default(),
self.decimals as u8,
self.decimals,
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,8 @@ fn generate_system_txs(
if use_randomized_compute_unit_price {
let mut rng = rand::thread_rng();
let range = Uniform::from(0..MAX_COMPUTE_UNIT_PRICE);
let compute_unit_prices: Vec<_> = (0..pairs.len())
.map(|_| range.sample(&mut rng) as u64)
.collect();
let compute_unit_prices: Vec<_> =
(0..pairs.len()).map(|_| range.sample(&mut rng)).collect();
let pairs_with_compute_unit_prices: Vec<_> =
pairs.iter().zip(compute_unit_prices.iter()).collect();

Expand Down
2 changes: 1 addition & 1 deletion bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<T: Clone + Copy> Bucket<T> {
let mut m = Measure::start("bucket_create_key");
let ix = Self::bucket_index_ix(index, key, random);
for i in ix..ix + index.max_search() {
let ii = i as u64 % index.capacity();
let ii = i % index.capacity();
if !index.is_free(ii) {
continue;
}
Expand Down
16 changes: 8 additions & 8 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ pub fn keypair_from_seed_phrase(
derivation_path: Option<DerivationPath>,
legacy: bool,
) -> Result<Keypair, Box<dyn error::Error>> {
let seed_phrase = prompt_password(&format!("[{}] seed phrase: ", keypair_name))?;
let seed_phrase = prompt_password(format!("[{}] seed phrase: ", keypair_name))?;
let seed_phrase = seed_phrase.trim();
let passphrase_prompt = format!(
"[{}] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue: ",
Expand Down Expand Up @@ -1184,7 +1184,7 @@ mod tests {
));
let stdin = "stdin:".to_string();
assert!(matches!(
parse_signer_source(&stdin).unwrap(),
parse_signer_source(stdin).unwrap(),
SignerSource {
kind: SignerSourceKind::Stdin,
derivation_path: None,
Expand All @@ -1201,7 +1201,7 @@ mod tests {
));
let pubkey = Pubkey::new_unique();
assert!(
matches!(parse_signer_source(&pubkey.to_string()).unwrap(), SignerSource {
matches!(parse_signer_source(pubkey.to_string()).unwrap(), SignerSource {
kind: SignerSourceKind::Pubkey(p),
derivation_path: None,
legacy: false,
Expand Down Expand Up @@ -1241,7 +1241,7 @@ mod tests {
manufacturer: Manufacturer::Ledger,
pubkey: None,
};
assert!(matches!(parse_signer_source(&usb).unwrap(), SignerSource {
assert!(matches!(parse_signer_source(usb).unwrap(), SignerSource {
kind: SignerSourceKind::Usb(u),
derivation_path: None,
legacy: false,
Expand All @@ -1252,7 +1252,7 @@ mod tests {
pubkey: None,
};
let expected_derivation_path = Some(DerivationPath::new_bip44(Some(0), Some(0)));
assert!(matches!(parse_signer_source(&usb).unwrap(), SignerSource {
assert!(matches!(parse_signer_source(usb).unwrap(), SignerSource {
kind: SignerSourceKind::Usb(u),
derivation_path: d,
legacy: false,
Expand All @@ -1267,22 +1267,22 @@ mod tests {

let prompt = "prompt:".to_string();
assert!(matches!(
parse_signer_source(&prompt).unwrap(),
parse_signer_source(prompt).unwrap(),
SignerSource {
kind: SignerSourceKind::Prompt,
derivation_path: None,
legacy: false,
}
));
assert!(
matches!(parse_signer_source(&format!("file:{}", absolute_path_str)).unwrap(), SignerSource {
matches!(parse_signer_source(format!("file:{}", absolute_path_str)).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
} if p == absolute_path_str)
);
assert!(
matches!(parse_signer_source(&format!("file:{}", relative_path_str)).unwrap(), SignerSource {
matches!(parse_signer_source(format!("file:{}", relative_path_str)).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
Expand Down
16 changes: 8 additions & 8 deletions clap-v3-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ pub fn keypair_from_seed_phrase(
derivation_path: Option<DerivationPath>,
legacy: bool,
) -> Result<Keypair, Box<dyn error::Error>> {
let seed_phrase = prompt_password(&format!("[{}] seed phrase: ", keypair_name))?;
let seed_phrase = prompt_password(format!("[{}] seed phrase: ", keypair_name))?;
let seed_phrase = seed_phrase.trim();
let passphrase_prompt = format!(
"[{}] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue: ",
Expand Down Expand Up @@ -1184,7 +1184,7 @@ mod tests {
));
let stdin = "stdin:".to_string();
assert!(matches!(
parse_signer_source(&stdin).unwrap(),
parse_signer_source(stdin).unwrap(),
SignerSource {
kind: SignerSourceKind::Stdin,
derivation_path: None,
Expand All @@ -1201,7 +1201,7 @@ mod tests {
));
let pubkey = Pubkey::new_unique();
assert!(
matches!(parse_signer_source(&pubkey.to_string()).unwrap(), SignerSource {
matches!(parse_signer_source(pubkey.to_string()).unwrap(), SignerSource {
kind: SignerSourceKind::Pubkey(p),
derivation_path: None,
legacy: false,
Expand Down Expand Up @@ -1241,7 +1241,7 @@ mod tests {
manufacturer: Manufacturer::Ledger,
pubkey: None,
};
assert!(matches!(parse_signer_source(&usb).unwrap(), SignerSource {
assert!(matches!(parse_signer_source(usb).unwrap(), SignerSource {
kind: SignerSourceKind::Usb(u),
derivation_path: None,
legacy: false,
Expand All @@ -1252,7 +1252,7 @@ mod tests {
pubkey: None,
};
let expected_derivation_path = Some(DerivationPath::new_bip44(Some(0), Some(0)));
assert!(matches!(parse_signer_source(&usb).unwrap(), SignerSource {
assert!(matches!(parse_signer_source(usb).unwrap(), SignerSource {
kind: SignerSourceKind::Usb(u),
derivation_path: d,
legacy: false,
Expand All @@ -1267,22 +1267,22 @@ mod tests {

let prompt = "prompt:".to_string();
assert!(matches!(
parse_signer_source(&prompt).unwrap(),
parse_signer_source(prompt).unwrap(),
SignerSource {
kind: SignerSourceKind::Prompt,
derivation_path: None,
legacy: false,
}
));
assert!(
matches!(parse_signer_source(&format!("file:{}", absolute_path_str)).unwrap(), SignerSource {
matches!(parse_signer_source(format!("file:{}", absolute_path_str)).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
} if p == absolute_path_str)
);
assert!(
matches!(parse_signer_source(&format!("file:{}", relative_path_str)).unwrap(), SignerSource {
matches!(parse_signer_source(format!("file:{}", relative_path_str)).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
Expand Down
2 changes: 1 addition & 1 deletion cli-config/src/config_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ConfigInput {
(SettingType::Explicit, json_rpc_cfg_url.to_string()),
(SettingType::SystemDefault, Self::default_json_rpc_url()),
]);
(setting_type, normalize_to_url_if_moniker(&url_or_moniker))
(setting_type, normalize_to_url_if_moniker(url_or_moniker))
}

pub fn compute_keypair_path_setting(
Expand Down
2 changes: 1 addition & 1 deletion cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ pub fn return_signers_data(tx: &Transaction, config: &ReturnSignersConfig) -> Cl
});
let message = if config.dump_transaction_message {
let message_data = tx.message_data();
Some(base64::encode(&message_data))
Some(base64::encode(message_data))
} else {
None
};
Expand Down
6 changes: 3 additions & 3 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ pub fn process_catchup(
let average_time_remaining = if slot_distance == 0 || total_sleep_interval == 0 {
"".to_string()
} else {
let distance_delta = start_slot_distance as i64 - slot_distance as i64;
let distance_delta = start_slot_distance - slot_distance;
let average_catchup_slots_per_second =
distance_delta as f64 / f64::from(total_sleep_interval);
let average_time_remaining =
Expand All @@ -874,7 +874,7 @@ pub fn process_catchup(
let average_node_slots_per_second =
total_node_slot_delta as f64 / f64::from(total_sleep_interval);
let expected_finish_slot = (node_slot as f64
+ average_time_remaining as f64 * average_node_slots_per_second as f64)
+ average_time_remaining * average_node_slots_per_second)
.round();
format!(
" (AVG: {:.1} slots/second, ETA: slot {} in {})",
Expand Down Expand Up @@ -2214,7 +2214,7 @@ mod tests {
let default_keypair = Keypair::new();
let (default_keypair_file, mut tmp_file) = make_tmp_file();
write_keypair(&default_keypair, tmp_file.as_file_mut()).unwrap();
let default_signer = DefaultSigner::new("", &default_keypair_file);
let default_signer = DefaultSigner::new("", default_keypair_file);

let test_cluster_version = test_commands
.clone()
Expand Down
4 changes: 2 additions & 2 deletions core/benches/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn build_packet_batch(
1,
recent_blockhash.unwrap_or_else(Hash::new_unique),
);
let mut packet = Packet::from_data(None, &tx).unwrap();
let mut packet = Packet::from_data(None, tx).unwrap();
packet.meta.sender_stake = sender_stake as u64;
packet
})
Expand All @@ -64,7 +64,7 @@ fn build_randomized_packet_batch(
1,
recent_blockhash.unwrap_or_else(Hash::new_unique),
);
let mut packet = Packet::from_data(None, &tx).unwrap();
let mut packet = Packet::from_data(None, tx).unwrap();
let sender_stake = distribution.sample(&mut rng);
packet.meta.sender_stake = sender_stake as u64;
packet
Expand Down
9 changes: 4 additions & 5 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,7 @@ impl BankingStage {
"filter_pending_packets_time",
);
let filter_retryable_packets_us = filter_retryable_packets_time.as_us();
slot_metrics_tracker
.increment_filter_retryable_packets_us(filter_retryable_packets_us as u64);
slot_metrics_tracker.increment_filter_retryable_packets_us(filter_retryable_packets_us);
banking_stage_stats
.filter_pending_packets_elapsed
.fetch_add(filter_retryable_packets_us, Ordering::Relaxed);
Expand Down Expand Up @@ -3993,7 +3992,7 @@ mod tests {
1,
Hash::new_unique(),
);
let packet = Packet::from_data(None, &tx).unwrap();
let packet = Packet::from_data(None, tx).unwrap();
let deserialized_packet = DeserializedPacket::new(packet).unwrap();

let genesis_config_info = create_slow_genesis_config(10_000);
Expand Down Expand Up @@ -4084,15 +4083,15 @@ mod tests {
let fwd_block_hash = Hash::new_unique();
let forwarded_packet = {
let transaction = system_transaction::transfer(&keypair, &pubkey, 1, fwd_block_hash);
let mut packet = Packet::from_data(None, &transaction).unwrap();
let mut packet = Packet::from_data(None, transaction).unwrap();
packet.meta.flags |= PacketFlags::FORWARDED;
DeserializedPacket::new(packet).unwrap()
};

let normal_block_hash = Hash::new_unique();
let normal_packet = {
let transaction = system_transaction::transfer(&keypair, &pubkey, 1, normal_block_hash);
let packet = Packet::from_data(None, &transaction).unwrap();
let packet = Packet::from_data(None, transaction).unwrap();
DeserializedPacket::new(packet).unwrap()
};

Expand Down
2 changes: 1 addition & 1 deletion core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl ClusterInfoVoteListener {
}
}

if time_since_lock.elapsed().as_millis() > BANK_SEND_VOTES_LOOP_SLEEP_MS as u128 {
if time_since_lock.elapsed().as_millis() > BANK_SEND_VOTES_LOOP_SLEEP_MS {
// Always set this to avoid taking the poh lock too often
time_since_lock = Instant::now();
// We will take this lock at most once every `BANK_SEND_VOTES_LOOP_SLEEP_MS`
Expand Down
2 changes: 1 addition & 1 deletion core/src/forward_packet_batches_by_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod tests {
) -> DeserializedPacket {
let tx =
system_transaction::transfer(&Keypair::new(), write_to_account, 1, Hash::new_unique());
let packet = Packet::from_data(None, &tx).unwrap();
let packet = Packet::from_data(None, tx).unwrap();
DeserializedPacket::new_with_priority_details(
packet,
TransactionPriorityDetails {
Expand Down
2 changes: 1 addition & 1 deletion core/src/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {
1,
Hash::new_unique(),
);
let packet = Packet::from_data(None, &tx).unwrap();
let packet = Packet::from_data(None, tx).unwrap();
let deserialized_packet = ImmutableDeserializedPacket::new(packet, None);

assert!(matches!(deserialized_packet, Ok(_)));
Expand Down
2 changes: 1 addition & 1 deletion core/src/leader_slot_banking_stage_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl LeaderSlotMetricsTracker {
.timing_metrics
.process_packets_timings
.cost_model_us,
*cost_model_us as u64
*cost_model_us
);

leader_slot_metrics
Expand Down
4 changes: 2 additions & 2 deletions core/src/ledger_cleanup_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ impl LedgerCleanupService {
max_ledger_shreds,
iterate_time
);
if (total_shreds as u64) < max_ledger_shreds {
if total_shreds < max_ledger_shreds {
return (false, 0, total_shreds);
}
let mut num_shreds_to_clean = 0;
let mut lowest_cleanup_slot = total_slots[0].0;
for (slot, num_shreds) in total_slots.iter().rev() {
num_shreds_to_clean += *num_shreds as u64;
num_shreds_to_clean += *num_shreds;
if num_shreds_to_clean > max_ledger_shreds {
lowest_cleanup_slot = *slot;
break;
Expand Down
10 changes: 5 additions & 5 deletions core/src/repair_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ mod test {
let num_slots = 2;

// Create some shreds
let (mut shreds, _) = make_many_slot_entries(0, num_slots as u64, 150);
let (mut shreds, _) = make_many_slot_entries(0, num_slots, 150);
let num_shreds = shreds.len() as u64;
let num_shreds_per_slot = num_shreds / num_slots;

Expand Down Expand Up @@ -856,7 +856,7 @@ mod test {
.flat_map(|slot| {
missing_indexes_per_slot
.iter()
.map(move |shred_index| ShredRepairType::Shred(slot as u64, *shred_index))
.map(move |shred_index| ShredRepairType::Shred(slot, *shred_index))
})
.collect();

Expand Down Expand Up @@ -969,10 +969,10 @@ mod test {
let expected: Vec<ShredRepairType> = (repair_slot_range.start
..=repair_slot_range.end)
.map(|slot_index| {
if slots.contains(&(slot_index as u64)) {
ShredRepairType::Shred(slot_index as u64, 0)
if slots.contains(&slot_index) {
ShredRepairType::Shred(slot_index, 0)
} else {
ShredRepairType::HighestShred(slot_index as u64, 0)
ShredRepairType::HighestShred(slot_index, 0)
}
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4297,7 +4297,7 @@ pub(crate) mod tests {
assert!(blockstore.is_dead(bank1.slot()));
res.map(|_| ())
};
let _ignored = remove_dir_all(&ledger_path);
let _ignored = remove_dir_all(ledger_path);
res
}

Expand Down
Loading

0 comments on commit d1ba421

Please sign in to comment.