Skip to content

Commit

Permalink
patches clippy errors from new rust nightly release (solana-labs#27996)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored Sep 22, 2022
1 parent ff71df4 commit 9a57c64
Show file tree
Hide file tree
Showing 64 changed files with 155 additions and 177 deletions.
5 changes: 1 addition & 4 deletions account-decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ impl UiAccount {
{
UiAccountData::Json(parsed_data)
} else {
UiAccountData::Binary(
base64::encode(&account.data()),
UiAccountEncoding::Base64,
)
UiAccountData::Binary(base64::encode(account.data()), UiAccountEncoding::Base64)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion bench-streamer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn producer(addr: &SocketAddr, exit: Arc<AtomicBool>) -> JoinHandle<()> {
let a = p.meta.socket_addr();
assert!(p.meta.size <= PACKET_DATA_SIZE);
let data = p.data(..).unwrap_or_default();
send.send_to(data, &a).unwrap();
send.send_to(data, a).unwrap();
num += 1;
}
assert_eq!(num, 10);
Expand Down
4 changes: 2 additions & 2 deletions bucket_map/src/bucket_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl<T: Clone + Copy + Debug> BucketMap<T> {

fn erase_previous_drives(drives: &[PathBuf]) {
drives.iter().for_each(|folder| {
let _ = fs::remove_dir_all(&folder);
let _ = fs::create_dir_all(&folder);
let _ = fs::remove_dir_all(folder);
let _ = fs::create_dir_all(folder);
})
}

Expand Down
2 changes: 1 addition & 1 deletion clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ mod tests {
} if p == absolute_path_str)
);
assert!(
matches!(parse_signer_source(&relative_path_str).unwrap(), SignerSource {
matches!(parse_signer_source(relative_path_str).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
Expand Down
2 changes: 1 addition & 1 deletion clap-v3-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ mod tests {
} if p == absolute_path_str)
);
assert!(
matches!(parse_signer_source(&relative_path_str).unwrap(), SignerSource {
matches!(parse_signer_source(relative_path_str).unwrap(), SignerSource {
kind: SignerSourceKind::Filepath(p),
derivation_path: None,
legacy: false,
Expand Down
4 changes: 2 additions & 2 deletions cli-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy_static! {
/// [lazy_static]: https://docs.rs/lazy_static
pub static ref CONFIG_FILE: Option<String> = {
dirs_next::home_dir().map(|mut path| {
path.extend(&[".config", "solana", "cli", "config.yml"]);
path.extend([".config", "solana", "cli", "config.yml"]);
path.to_str().unwrap().to_string()
})
};
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Default for Config {
fn default() -> Self {
let keypair_path = {
let mut keypair_path = dirs_next::home_dir().expect("home directory");
keypair_path.extend(&[".config", "solana", "id.json"]);
keypair_path.extend([".config", "solana", "id.json"]);
keypair_path.to_str().unwrap().to_string()
};
let json_rpc_url = "https://api.mainnet-beta.solana.com".to_string();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ pub fn process_transaction_history(
Some(status) => format!("{:?}", status),
}
},
result.memo.unwrap_or_else(|| "".to_string()),
result.memo.unwrap_or_default(),
);
} else {
println!("{}", result.signature);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ fn get_default_program_keypair(program_location: &Option<String>) -> Keypair {
filename.push("-keypair");
keypair_file.set_file_name(filename);
keypair_file.set_extension("json");
if let Ok(keypair) = read_keypair_file(&keypair_file.to_str().unwrap()) {
if let Ok(keypair) = read_keypair_file(keypair_file.to_str().unwrap()) {
keypair
} else {
Keypair::new()
Expand Down
2 changes: 1 addition & 1 deletion core/src/broadcast_stage/broadcast_fake_shreds_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl BroadcastRun for BroadcastFakeShredsRun {
if fake == (i <= self.partition) {
// Send fake shreds to the first N peers
data_shreds.iter().for_each(|b| {
sock.send_to(b.payload(), &peer.tvu_forwards).unwrap();
sock.send_to(b.payload(), peer.tvu_forwards).unwrap();
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ pub mod test {
OpenOptions::new()
.write(true)
.truncate(true)
.open(&path)
.open(path)
.unwrap_or_else(|_| panic!("Failed to truncate file: {:?}", path));
},
);
Expand Down
11 changes: 3 additions & 8 deletions core/src/repair_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,9 @@ impl RepairWeight {
.get_mut(&orphan_tree_root)
.expect("Orphan must exist");

let num_skip = if parent_tree_root.is_some() {
// Skip the leaf of the parent tree that the
// orphan would merge with later in a call
// to `merge_trees`
1
} else {
0
};
// Skip the leaf of the parent tree that the orphan would merge
// with later in a call to `merge_trees`
let num_skip = usize::from(parent_tree_root.is_some());

for ancestor in new_ancestors.iter().skip(num_skip).rev() {
self.slot_to_tree.insert(*ancestor, orphan_tree_root);
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 @@ -935,7 +935,7 @@ impl ReplayStage {
replay_active_banks_time.as_us(),
wait_receive_time.as_us(),
heaviest_fork_failures_time.as_us(),
if did_complete_bank {1} else {0},
u64::from(did_complete_bank),
process_gossip_duplicate_confirmed_slots_time.as_us(),
process_unfrozen_gossip_verified_vote_hashes_time.as_us(),
process_duplicate_slots_time.as_us(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/snapshot_packager_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ mod tests {
.collect();

// Create directory of hard links for snapshots
let link_snapshots_dir = tempfile::tempdir_in(&temp_dir).unwrap();
let link_snapshots_dir = tempfile::tempdir_in(temp_dir).unwrap();
for snapshots_path in snapshots_paths {
let snapshot_file_name = snapshots_path.file_name().unwrap();
let link_snapshots_dir = link_snapshots_dir.path().join(snapshot_file_name);
Expand Down
2 changes: 1 addition & 1 deletion core/src/tower_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl TowerStorage for FileTowerStorage {
trace!("load {}", filename.display());

// Ensure to create parent dir here, because restore() precedes save() always
fs::create_dir_all(&filename.parent().unwrap())?;
fs::create_dir_all(filename.parent().unwrap())?;

if let Ok(file) = File::open(&filename) {
// New format
Expand Down
2 changes: 1 addition & 1 deletion core/src/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ mod tests {
let capacity = transactions.len();
let mut packet_vector = Vec::with_capacity(capacity);
for tx in transactions.iter() {
packet_vector.push(Packet::from_data(None, &tx).unwrap());
packet_vector.push(Packet::from_data(None, tx).unwrap());
}
for index in vote_indexes.iter() {
packet_vector[*index].meta.flags |= PacketFlags::SIMPLE_VOTE_TX;
Expand Down
4 changes: 2 additions & 2 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ pub fn move_and_async_delete_path(path: impl AsRef<Path> + Copy) {
return;
}

if let Err(err) = std::fs::rename(&path, &path_delete) {
if let Err(err) = std::fs::rename(path, &path_delete) {
warn!(
"Path renaming failed: {}. Falling back to rm_dir in sync mode",
err.to_string()
Expand All @@ -2094,7 +2094,7 @@ pub fn move_and_async_delete_path(path: impl AsRef<Path> + Copy) {
/// to delete the top level directory it might be able to
/// delete the contents of that directory.
fn delete_contents_of_path(path: impl AsRef<Path> + Copy) {
if let Ok(dir_entries) = std::fs::read_dir(&path) {
if let Ok(dir_entries) = std::fs::read_dir(path) {
for entry in dir_entries.flatten() {
let sub_path = entry.path();
let metadata = match entry.metadata() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/warm_quic_cache_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl WarmQuicCacheService {
.lookup_contact_info(&leader_pubkey, |leader| leader.tpu)
{
let conn = connection_cache.get_connection(&addr);
if let Err(err) = conn.send_wire_transaction(&[0u8]) {
if let Err(err) = conn.send_wire_transaction([0u8]) {
warn!(
"Failed to warmup QUIC connection to the leader {:?}, Error {:?}",
leader_pubkey, err
Expand Down
2 changes: 1 addition & 1 deletion core/src/window_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl WindowService {
&verified_receiver,
&blockstore,
&leader_schedule_cache,
&handle_duplicate,
handle_duplicate,
&mut metrics,
&mut ws_metrics,
&completed_data_sets_sender,
Expand Down
2 changes: 1 addition & 1 deletion core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ fn test_concurrent_snapshot_packaging(
// currently sitting in the channel
snapshot_utils::purge_old_bank_snapshots(bank_snapshots_dir);

let mut bank_snapshots = snapshot_utils::get_bank_snapshots_pre(&bank_snapshots_dir);
let mut bank_snapshots = snapshot_utils::get_bank_snapshots_pre(bank_snapshots_dir);
bank_snapshots.sort_unstable();
assert!(bank_snapshots
.into_iter()
Expand Down
6 changes: 3 additions & 3 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl ClusterInfo {
let filename = self.contact_info_path.join("contact-info.bin");
let tmp_filename = &filename.with_extension("tmp");

match File::create(&tmp_filename) {
match File::create(tmp_filename) {
Ok(mut file) => {
if let Err(err) = bincode::serialize_into(&mut file, &nodes) {
warn!(
Expand All @@ -565,7 +565,7 @@ impl ClusterInfo {
}
}

match fs::rename(&tmp_filename, &filename) {
match fs::rename(tmp_filename, &filename) {
Ok(()) => {
info!(
"Saved contact info for {} nodes into {}",
Expand Down Expand Up @@ -1097,7 +1097,7 @@ impl ClusterInfo {
) -> Result<(), GossipError> {
let tpu = tpu.unwrap_or_else(|| self.my_contact_info().tpu);
let buf = serialize(transaction)?;
self.socket.send_to(&buf, &tpu)?;
self.socket.send_to(&buf, tpu)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn extract_release_archive(
progress_bar.set_message(format!("{}Extracting...", PACKAGE));

if extract_dir.exists() {
let _ = fs::remove_dir_all(&extract_dir);
let _ = fs::remove_dir_all(extract_dir);
}

let tmp_extract_dir = extract_dir.with_file_name("tmp-extract");
Expand All @@ -188,7 +188,7 @@ fn extract_release_archive(
}

fn load_release_version(version_yml: &Path) -> Result<ReleaseVersion, String> {
let file = File::open(&version_yml)
let file = File::open(version_yml)
.map_err(|err| format!("Unable to open {:?}: {:?}", version_yml, err))?;
let version: ReleaseVersion = serde_yaml::from_reader(file)
.map_err(|err| format!("Unable to parse {:?}: {:?}", version_yml, err))?;
Expand Down
6 changes: 3 additions & 3 deletions install/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ pub const JSON_RPC_URL: &str = "http://api.devnet.solana.com";
lazy_static! {
pub static ref CONFIG_FILE: Option<String> = {
dirs_next::home_dir().map(|mut path| {
path.extend(&[".config", "solana", "install", "config.yml"]);
path.extend([".config", "solana", "install", "config.yml"]);
path.to_str().unwrap().to_string()
})
};
pub static ref USER_KEYPAIR: Option<String> = {
dirs_next::home_dir().map(|mut path| {
path.extend(&[".config", "solana", "id.json"]);
path.extend([".config", "solana", "id.json"]);
path.to_str().unwrap().to_string()
})
};
pub static ref DATA_DIR: Option<String> = {
dirs_next::home_dir().map(|mut path| {
path.extend(&[".local", "share", "solana", "install"]);
path.extend([".local", "share", "solana", "install"]);
path.to_str().unwrap().to_string()
})
};
Expand Down
10 changes: 5 additions & 5 deletions keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const NO_OUTFILE_ARG: ArgConstant<'static> = ArgConstant {
fn word_count_arg<'a>() -> Arg<'a> {
Arg::new(WORD_COUNT_ARG.name)
.long(WORD_COUNT_ARG.long)
.possible_values(&["12", "15", "18", "21", "24"])
.possible_values(["12", "15", "18", "21", "24"])
.default_value("12")
.value_name("NUMBER")
.takes_value(true)
Expand All @@ -83,7 +83,7 @@ fn word_count_arg<'a>() -> Arg<'a> {
fn language_arg<'a>() -> Arg<'a> {
Arg::new(LANGUAGE_ARG.name)
.long(LANGUAGE_ARG.long)
.possible_values(&[
.possible_values([
"english",
"chinese-simplified",
"chinese-traditional",
Expand Down Expand Up @@ -143,7 +143,7 @@ fn get_keypair_from_matches(
} else if !config.keypair_path.is_empty() {
&config.keypair_path
} else {
path.extend(&[".config", "solana", "id.json"]);
path.extend([".config", "solana", "id.json"]);
path.to_str().unwrap()
};
signer_from_path(matches, path, "pubkey recovery", wallet_manager)
Expand Down Expand Up @@ -597,7 +597,7 @@ fn do_main(matches: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
} else if matches.is_present(NO_OUTFILE_ARG.name) {
None
} else {
path.extend(&[".config", "solana", "id.json"]);
path.extend([".config", "solana", "id.json"]);
Some(path.to_str().unwrap())
};

Expand Down Expand Up @@ -646,7 +646,7 @@ fn do_main(matches: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
let outfile = if matches.is_present("outfile") {
matches.value_of("outfile").unwrap()
} else {
path.extend(&[".config", "solana", "id.json"]);
path.extend([".config", "solana", "id.json"]);
path.to_str().unwrap()
};

Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub async fn transaction_history(
"{}, slot={}, memo=\"{}\", status={}",
result.signature,
result.slot,
result.memo.unwrap_or_else(|| "".to_string()),
result.memo.unwrap_or_default(),
match result.err {
None => "Confirmed".to_string(),
Some(err) => format!("Failed: {:?}", err),
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/ledger_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn parse_ledger_path(matches: &ArgMatches<'_>, name: &str) -> PathBuf {

// Canonicalize ledger path to avoid issues with symlink creation
pub fn canonicalize_ledger_path(ledger_path: &Path) -> PathBuf {
fs::canonicalize(&ledger_path).unwrap_or_else(|err| {
fs::canonicalize(ledger_path).unwrap_or_else(|err| {
eprintln!(
"Unable to access ledger path '{}': {}",
ledger_path.display(),
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Blockstore {
}

fn do_open(ledger_path: &Path, options: BlockstoreOptions) -> Result<Blockstore> {
fs::create_dir_all(&ledger_path)?;
fs::create_dir_all(ledger_path)?;
let blockstore_path = ledger_path.join(
options
.column_options
Expand Down Expand Up @@ -2579,7 +2579,7 @@ impl Blockstore {
// Check the active_transaction_status_index to see if it contains slot. If so, start with
// that index, as it will contain higher slots
let starting_primary_index = *self.active_transaction_status_index.read().unwrap();
let next_primary_index = if starting_primary_index == 0 { 1 } else { 0 };
let next_primary_index = u64::from(starting_primary_index == 0);
let next_max_slot = self
.transaction_status_index_cf
.get(next_primary_index)?
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Rocks {
let access_type = options.access_type.clone();
let recovery_mode = options.recovery_mode.clone();

fs::create_dir_all(&path)?;
fs::create_dir_all(path)?;

// Use default database options
if should_disable_auto_compactions(&access_type) {
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/sigverify_shreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn sign_shreds_gpu_pinned_keypair(keypair: &Keypair, cache: &RecyclerCache)
let pubkey = keypair.pubkey().to_bytes();
let secret = keypair.secret().to_bytes();
let mut hasher = Sha512::default();
hasher.update(&secret);
hasher.update(secret);
let mut result = hasher.finalize();
result[0] &= 248;
result[31] &= 63;
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ fn test_snapshots_blockstore_floor() {

let archive_info = loop {
let archive =
snapshot_utils::get_highest_full_snapshot_archive_info(&full_snapshot_archives_dir);
snapshot_utils::get_highest_full_snapshot_archive_info(full_snapshot_archives_dir);
if archive.is_some() {
trace!("snapshot exists");
break archive.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion net-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub fn bind_common(
let addr = SocketAddr::new(ip_addr, port);
let sock_addr = SockAddr::from(addr);
sock.bind(&sock_addr)
.and_then(|_| TcpListener::bind(&addr).map(|listener| (sock.into(), listener)))
.and_then(|_| TcpListener::bind(addr).map(|listener| (sock.into(), listener)))
}

pub fn bind_two_in_range_with_offset(
Expand Down
2 changes: 1 addition & 1 deletion perf/src/perf_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn find_cuda_home(perf_libs_path: &Path) -> Option<PathBuf> {
}

// Search /usr/local for a `cuda-` directory that matches a perf-libs subdirectory
for entry in fs::read_dir(&perf_libs_path).unwrap().flatten() {
for entry in fs::read_dir(perf_libs_path).unwrap().flatten() {
let path = entry.path();
if !path.is_dir() {
continue;
Expand Down
Loading

0 comments on commit 9a57c64

Please sign in to comment.