Clippy work towards rust 1.38 (#6219)

This commit is contained in:
Michael Vines 2019-10-02 18:04:18 -07:00 committed by GitHub
parent c06876eb3d
commit 13fc518268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 75 additions and 78 deletions

View File

@ -61,10 +61,12 @@ impl RpcClient {
Err(io::Error::new( Err(io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
"Received result of an unexpected type", "Received result of an unexpected type",
))?; )
} .into())
} else {
Ok(signature.as_str().unwrap().to_string()) Ok(signature.as_str().unwrap().to_string())
} }
}
pub fn get_signature_status( pub fn get_signature_status(
&self, &self,
@ -195,14 +197,11 @@ impl RpcClient {
send_retries - 1 send_retries - 1
}; };
if send_retries == 0 { if send_retries == 0 {
if status.is_some() { return Err(io::Error::new(
status.unwrap()?
} else {
Err(io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
format!("Transaction {:?} failed: {:?}", signature_str, status), format!("Transaction {:?} failed: {:?}", signature_str, status),
))?; )
} .into());
} }
} }
} }
@ -262,7 +261,7 @@ impl RpcClient {
} }
if send_retries == 0 { if send_retries == 0 {
Err(io::Error::new(io::ErrorKind::Other, "Transactions failed"))?; return Err(io::Error::new(io::ErrorKind::Other, "Transactions failed").into());
} }
send_retries -= 1; send_retries -= 1;

View File

@ -53,10 +53,11 @@ impl GenericRpcClientRequest for RpcClientRequest {
Ok(mut response) => { Ok(mut response) => {
let json: serde_json::Value = serde_json::from_str(&response.text()?)?; let json: serde_json::Value = serde_json::from_str(&response.text()?)?;
if json["error"].is_object() { if json["error"].is_object() {
Err(RpcError::RpcRequestError(format!( return Err(RpcError::RpcRequestError(format!(
"RPC Error response: {}", "RPC Error response: {}",
serde_json::to_string(&json["error"]).unwrap() serde_json::to_string(&json["error"]).unwrap()
)))? ))
.into());
} }
return Ok(json["result"].clone()); return Ok(json["result"].clone());
} }
@ -66,7 +67,7 @@ impl GenericRpcClientRequest for RpcClientRequest {
request, retries, e request, retries, e
); );
if retries == 0 { if retries == 0 {
Err(e)?; return Err(e.into());
} }
retries -= 1; retries -= 1;

View File

@ -339,7 +339,7 @@ impl SyncClient for ThinClient {
} }
Err(e) => { Err(e) => {
self.optimizer.report(index, std::u64::MAX); self.optimizer.report(index, std::u64::MAX);
Err(e)? Err(e.into())
} }
} }
} }
@ -380,7 +380,7 @@ impl SyncClient for ThinClient {
} }
Err(e) => { Err(e) => {
self.optimizer.report(index, std::u64::MAX); self.optimizer.report(index, std::u64::MAX);
Err(e)? Err(e.into())
} }
} }
} }

View File

@ -213,13 +213,13 @@ pub fn request_airdrop_transaction(
})?; })?;
let transaction_length = LittleEndian::read_u16(&buffer) as usize; let transaction_length = LittleEndian::read_u16(&buffer) as usize;
if transaction_length >= PACKET_DATA_SIZE { if transaction_length >= PACKET_DATA_SIZE {
Err(Error::new( return Err(Error::new(
ErrorKind::Other, ErrorKind::Other,
format!( format!(
"request_airdrop_transaction: invalid transaction_length from drone: {}", "request_airdrop_transaction: invalid transaction_length from drone: {}",
transaction_length transaction_length
), ),
))?; ));
} }
// Read the transaction // Read the transaction
@ -265,11 +265,8 @@ pub fn run_drone(
send_addr: Option<Sender<SocketAddr>>, send_addr: Option<Sender<SocketAddr>>,
) { ) {
let socket = TcpListener::bind(&drone_addr).unwrap(); let socket = TcpListener::bind(&drone_addr).unwrap();
if send_addr.is_some() { if let Some(send_addr) = send_addr {
send_addr send_addr.send(socket.local_addr().unwrap()).unwrap();
.unwrap()
.send(socket.local_addr().unwrap())
.unwrap();
} }
info!("Drone started. Listening on: {}", drone_addr); info!("Drone started. Listening on: {}", drone_addr);
let done = socket let done = socket

View File

@ -13,11 +13,12 @@ pub fn request_airdrop_transaction(
_blockhash: Hash, _blockhash: Hash,
) -> Result<Transaction, Error> { ) -> Result<Transaction, Error> {
if lamports == 0 { if lamports == 0 {
Err(Error::new(ErrorKind::Other, "Airdrop failed"))? Err(Error::new(ErrorKind::Other, "Airdrop failed"))
} } else {
let key = Keypair::new(); let key = Keypair::new();
let to = Pubkey::new_rand(); let to = Pubkey::new_rand();
let blockhash = Hash::default(); let blockhash = Hash::default();
let tx = system_transaction::create_user_account(&key, &to, lamports, blockhash); let tx = system_transaction::create_user_account(&key, &to, lamports, blockhash);
Ok(tx) Ok(tx)
}
} }

View File

@ -127,7 +127,7 @@ fn download_to_temp_archive(
.map_err(|err| format!("Unable to hash {:?}: {}", temp_file, err))?; .map_err(|err| format!("Unable to hash {:?}: {}", temp_file, err))?;
if expected_sha256.is_some() && expected_sha256 != Some(&temp_file_sha256) { if expected_sha256.is_some() && expected_sha256 != Some(&temp_file_sha256) {
Err(io::Error::new(io::ErrorKind::Other, "Incorrect hash"))?; return Err(io::Error::new(io::ErrorKind::Other, "Incorrect hash").into());
} }
source.progress_bar.finish_and_clear(); source.progress_bar.finish_and_clear();
@ -651,7 +651,7 @@ pub fn deploy(
})?; })?;
progress_bar.finish_and_clear(); progress_bar.finish_and_clear();
if balance.unwrap_or(0) == 0 { if balance.unwrap_or(0) == 0 {
Err(format!("{} account balance is empty", from_keypair_file))?; return Err(format!("{} account balance is empty", from_keypair_file));
} }
// Download the release // Download the release
@ -780,12 +780,12 @@ pub fn update(config_file: &str) -> Result<bool, String> {
if timestamp_secs() if timestamp_secs()
< u64::from_str_radix(crate::build_env::BUILD_SECONDS_SINCE_UNIX_EPOCH, 10).unwrap() < u64::from_str_radix(crate::build_env::BUILD_SECONDS_SINCE_UNIX_EPOCH, 10).unwrap()
{ {
Err("Unable to update as system time seems unreliable".to_string())? return Err("Unable to update as system time seems unreliable".to_string());
} }
if let Some(ref current_update_manifest) = config.current_update_manifest { if let Some(ref current_update_manifest) = config.current_update_manifest {
if update_manifest.timestamp_secs < current_update_manifest.timestamp_secs { if update_manifest.timestamp_secs < current_update_manifest.timestamp_secs {
Err("Unable to update to an older version".to_string())? return Err("Unable to update to an older version".to_string());
} }
} }
let release_dir = config.release_dir(&update_manifest.download_sha256); let release_dir = config.release_dir(&update_manifest.download_sha256);
@ -818,7 +818,7 @@ pub fn update(config_file: &str) -> Result<bool, String> {
})?; })?;
if release_target != crate::build_env::TARGET { if release_target != crate::build_env::TARGET {
Err(format!("Incompatible update target: {}", release_target))?; return Err(format!("Incompatible update target: {}", release_target));
} }
let _ = fs::remove_dir_all(config.active_release_dir()); let _ = fs::remove_dir_all(config.active_release_dir());
@ -854,10 +854,10 @@ pub fn run(
} }
if !full_program_path.exists() { if !full_program_path.exists() {
Err(format!( return Err(format!(
"{} does not exist", "{} does not exist",
full_program_path.to_str().unwrap() full_program_path.to_str().unwrap()
))?; ));
} }
let mut child_option: Option<std::process::Child> = None; let mut child_option: Option<std::process::Child> = None;

View File

@ -47,13 +47,11 @@ impl SignedUpdateManifest {
let mut manifest: SignedUpdateManifest = bincode::deserialize(input)?; let mut manifest: SignedUpdateManifest = bincode::deserialize(input)?;
manifest.account_pubkey = *account_pubkey; manifest.account_pubkey = *account_pubkey;
if !manifest.verify() { if !manifest.verify() {
Err(io::Error::new( Err(io::Error::new(io::ErrorKind::Other, "Manifest failed to verify").into())
io::ErrorKind::Other, } else {
"Manifest failed to verify",
))?;
}
Ok(manifest) Ok(manifest)
} }
}
} }
impl ConfigState for SignedUpdateManifest { impl ConfigState for SignedUpdateManifest {

View File

@ -33,7 +33,7 @@ pub fn process_instruction(
// or when no signers specified in Config data // or when no signers specified in Config data
if keyed_accounts[0].signer_key().is_none() { if keyed_accounts[0].signer_key().is_none() {
error!("account[0].signer_key().is_none()"); error!("account[0].signer_key().is_none()");
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
} }
@ -50,19 +50,19 @@ pub fn process_instruction(
let signer_account = keyed_accounts.get(account_index); let signer_account = keyed_accounts.get(account_index);
if signer_account.is_none() { if signer_account.is_none() {
error!("account {:?} is not in account list", signer); error!("account {:?} is not in account list", signer);
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
let signer_key = signer_account.unwrap().signer_key(); let signer_key = signer_account.unwrap().signer_key();
if signer_key.is_none() { if signer_key.is_none() {
error!("account {:?} signer_key().is_none()", signer); error!("account {:?} signer_key().is_none()", signer);
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
if signer_key.unwrap() != signer { if signer_key.unwrap() != signer {
error!( error!(
"account[{:?}].signer_key() does not match Config data)", "account[{:?}].signer_key() does not match Config data)",
account_index account_index
); );
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
// If Config account is already initialized, update signatures must match Config data // If Config account is already initialized, update signatures must match Config data
if !current_data.keys.is_empty() if !current_data.keys.is_empty()
@ -72,11 +72,11 @@ pub fn process_instruction(
.is_none() .is_none()
{ {
error!("account {:?} is not in stored signer list", signer); error!("account {:?} is not in stored signer list", signer);
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
} else if keyed_accounts[0].signer_key().is_none() { } else if keyed_accounts[0].signer_key().is_none() {
error!("account[0].signer_key().is_none()"); error!("account[0].signer_key().is_none()");
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
} }
@ -87,12 +87,12 @@ pub fn process_instruction(
counter, counter,
current_signer_keys.len() current_signer_keys.len()
); );
Err(InstructionError::MissingRequiredSignature)?; return Err(InstructionError::MissingRequiredSignature);
} }
if keyed_accounts[0].account.data.len() < data.len() { if keyed_accounts[0].account.data.len() < data.len() {
error!("instruction data too large"); error!("instruction data too large");
Err(InstructionError::InvalidInstructionData)?; return Err(InstructionError::InvalidInstructionData);
} }
keyed_accounts[0].account.data[0..data.len()].copy_from_slice(&data); keyed_accounts[0].account.data[0..data.len()].copy_from_slice(&data);

View File

@ -121,7 +121,7 @@ pub fn get_libra_balance<T: Client>(
} }
state => { state => {
info!("Unknown account state: {:?}", state); info!("Unknown account state: {:?}", state);
return Err(LibrapayError::UnknownAccountState)?; return Err(LibrapayError::UnknownAccountState.into());
} }
} }
let resource = data_store let resource = data_store

View File

@ -141,7 +141,7 @@ impl<'a> StorageAccount<'a> {
}; };
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::AccountAlreadyInitialized)? Err(InstructionError::AccountAlreadyInitialized)
} }
} }
@ -157,7 +157,7 @@ impl<'a> StorageAccount<'a> {
}; };
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::AccountAlreadyInitialized)? Err(InstructionError::AccountAlreadyInitialized)
} }
} }
@ -234,7 +234,7 @@ impl<'a> StorageAccount<'a> {
segment_proofs.push(proof); segment_proofs.push(proof);
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::InvalidArgument)? Err(InstructionError::InvalidArgument)
} }
} }
@ -270,7 +270,7 @@ impl<'a> StorageAccount<'a> {
credits.current_epoch += total_validations; credits.current_epoch += total_validations;
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::InvalidArgument)? Err(InstructionError::InvalidArgument)
} }
} }
@ -360,7 +360,7 @@ impl<'a> StorageAccount<'a> {
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::InvalidArgument)? Err(InstructionError::InvalidArgument)
} }
} }
@ -380,9 +380,9 @@ impl<'a> StorageAccount<'a> {
} = &mut storage_contract } = &mut storage_contract
{ {
if owner.id != *account_owner { if owner.id != *account_owner {
Err(InstructionError::CustomError( return Err(InstructionError::CustomError(
StorageError::InvalidOwner as u32, StorageError::InvalidOwner as u32,
))? ));
} }
credits.update_epoch(clock.epoch); credits.update_epoch(clock.epoch);
@ -397,9 +397,9 @@ impl<'a> StorageAccount<'a> {
} = &mut storage_contract } = &mut storage_contract
{ {
if owner.id != *account_owner { if owner.id != *account_owner {
Err(InstructionError::CustomError( return Err(InstructionError::CustomError(
StorageError::InvalidOwner as u32, StorageError::InvalidOwner as u32,
))? ));
} }
credits.update_epoch(clock.epoch); credits.update_epoch(clock.epoch);
let (num_validations, _total_proofs) = count_valid_proofs(&validations); let (num_validations, _total_proofs) = count_valid_proofs(&validations);
@ -409,7 +409,7 @@ impl<'a> StorageAccount<'a> {
self.account.set_state(storage_contract) self.account.set_state(storage_contract)
} else { } else {
Err(InstructionError::InvalidArgument)? Err(InstructionError::InvalidArgument)
} }
} }
} }
@ -424,8 +424,8 @@ fn check_redeemable(
if rewards_pool.account.lamports < rewards { if rewards_pool.account.lamports < rewards {
Err(InstructionError::CustomError( Err(InstructionError::CustomError(
StorageError::RewardPoolDepleted as u32, StorageError::RewardPoolDepleted as u32,
))? ))
} } else {
if rewards >= 1 { if rewards >= 1 {
rewards_pool.account.lamports -= rewards; rewards_pool.account.lamports -= rewards;
owner.account.lamports += rewards; owner.account.lamports += rewards;
@ -433,6 +433,7 @@ fn check_redeemable(
credits.redeemable = 0; credits.redeemable = 0;
} }
Ok(()) Ok(())
}
} }
pub fn create_rewards_pool() -> Account { pub fn create_rewards_pool() -> Account {

View File

@ -22,13 +22,13 @@ pub fn process_instruction(
match bincode::deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? { match bincode::deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
StorageInstruction::InitializeReplicatorStorage { owner } => { StorageInstruction::InitializeReplicatorStorage { owner } => {
if !rest.is_empty() { if !rest.is_empty() {
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
storage_account.initialize_replicator_storage(owner) storage_account.initialize_replicator_storage(owner)
} }
StorageInstruction::InitializeValidatorStorage { owner } => { StorageInstruction::InitializeValidatorStorage { owner } => {
if !rest.is_empty() { if !rest.is_empty() {
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
storage_account.initialize_validator_storage(owner) storage_account.initialize_validator_storage(owner)
} }
@ -40,7 +40,7 @@ pub fn process_instruction(
} => { } => {
if me_unsigned || rest.len() != 1 { if me_unsigned || rest.len() != 1 {
// This instruction must be signed by `me` // This instruction must be signed by `me`
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
let clock = sysvar::clock::from_keyed_account(&rest[0])?; let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.submit_mining_proof( storage_account.submit_mining_proof(
@ -54,14 +54,14 @@ pub fn process_instruction(
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => { StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => {
if me_unsigned || rest.len() != 1 { if me_unsigned || rest.len() != 1 {
// This instruction must be signed by `me` // This instruction must be signed by `me`
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
let clock = sysvar::clock::from_keyed_account(&rest[0])?; let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.advertise_storage_recent_blockhash(hash, segment, clock) storage_account.advertise_storage_recent_blockhash(hash, segment, clock)
} }
StorageInstruction::ClaimStorageReward => { StorageInstruction::ClaimStorageReward => {
if rest.len() != 4 { if rest.len() != 4 {
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
let (clock, rest) = rest.split_at_mut(1); let (clock, rest) = rest.split_at_mut(1);
let (rewards, rest) = rest.split_at_mut(1); let (rewards, rest) = rest.split_at_mut(1);
@ -75,13 +75,13 @@ pub fn process_instruction(
} }
StorageInstruction::ProofValidation { segment, proofs } => { StorageInstruction::ProofValidation { segment, proofs } => {
if rest.is_empty() { if rest.is_empty() {
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
let (clock, rest) = rest.split_at_mut(1); let (clock, rest) = rest.split_at_mut(1);
if me_unsigned || rest.is_empty() { if me_unsigned || rest.is_empty() {
// This instruction must be signed by `me` and `rest` cannot be empty // This instruction must be signed by `me` and `rest` cannot be empty
Err(InstructionError::InvalidArgument)?; return Err(InstructionError::InvalidArgument);
} }
let me_id = storage_account.id; let me_id = storage_account.id;
let clock = sysvar::clock::from_keyed_account(&clock[0])?; let clock = sysvar::clock::from_keyed_account(&clock[0])?;

View File

@ -166,7 +166,7 @@ pub fn process_instruction(
trace!("keyed_accounts: {:?}", keyed_accounts); trace!("keyed_accounts: {:?}", keyed_accounts);
if keyed_accounts.is_empty() { if keyed_accounts.is_empty() {
Err(InstructionError::InvalidInstructionData)?; return Err(InstructionError::InvalidInstructionData);
} }
// 0th index is vote account // 0th index is vote account
@ -184,7 +184,7 @@ pub fn process_instruction(
VoteInstruction::Vote(vote) => { VoteInstruction::Vote(vote) => {
datapoint_info!("vote-native", ("count", 1, i64)); datapoint_info!("vote-native", ("count", 1, i64));
if rest.len() < 2 { if rest.len() < 2 {
Err(InstructionError::InvalidInstructionData)?; return Err(InstructionError::InvalidInstructionData);
} }
let (slot_hashes_and_clock, other_signers) = rest.split_at_mut(2); let (slot_hashes_and_clock, other_signers) = rest.split_at_mut(2);
@ -198,7 +198,7 @@ pub fn process_instruction(
} }
VoteInstruction::Withdraw(lamports) => { VoteInstruction::Withdraw(lamports) => {
if rest.is_empty() { if rest.is_empty() {
Err(InstructionError::InvalidInstructionData)?; return Err(InstructionError::InvalidInstructionData);
} }
let (to, rest) = rest.split_at_mut(1); let (to, rest) = rest.split_at_mut(1);
let to = &mut to[0]; let to = &mut to[0];