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
12 changed files with 75 additions and 78 deletions

View File

@@ -33,7 +33,7 @@ pub fn process_instruction(
// or when no signers specified in Config data
if keyed_accounts[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);
if signer_account.is_none() {
error!("account {:?} is not in account list", signer);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
let signer_key = signer_account.unwrap().signer_key();
if signer_key.is_none() {
error!("account {:?} signer_key().is_none()", signer);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
if signer_key.unwrap() != signer {
error!(
"account[{:?}].signer_key() does not match Config data)",
account_index
);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
// If Config account is already initialized, update signatures must match Config data
if !current_data.keys.is_empty()
@@ -72,11 +72,11 @@ pub fn process_instruction(
.is_none()
{
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() {
error!("account[0].signer_key().is_none()");
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
}
@@ -87,12 +87,12 @@ pub fn process_instruction(
counter,
current_signer_keys.len()
);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
if keyed_accounts[0].account.data.len() < data.len() {
error!("instruction data too large");
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
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 => {
info!("Unknown account state: {:?}", state);
return Err(LibrapayError::UnknownAccountState)?;
return Err(LibrapayError::UnknownAccountState.into());
}
}
let resource = data_store

View File

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

View File

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

View File

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