chore: cargo +nightly clippy --fix -Z unstable-options

This commit is contained in:
Alexander Meißner
2021-06-18 15:34:46 +02:00
committed by Michael Vines
parent 3570b00560
commit 6514096a67
177 changed files with 1021 additions and 1021 deletions

View File

@ -107,9 +107,9 @@ fn bench_serialize_unaligned(bencher: &mut Bencher) {
.enumerate()
.map(|(i, (key, account))| {
if i <= accounts.len() / 2 {
KeyedAccount::new_readonly(&key, false, &account)
KeyedAccount::new_readonly(key, false, account)
} else {
KeyedAccount::new(&key, false, &account)
KeyedAccount::new(key, false, account)
}
})
.collect();
@ -128,9 +128,9 @@ fn bench_serialize_aligned(bencher: &mut Bencher) {
.enumerate()
.map(|(i, (key, account))| {
if i <= accounts.len() / 2 {
KeyedAccount::new_readonly(&key, false, &account)
KeyedAccount::new_readonly(key, false, account)
} else {
KeyedAccount::new(&key, false, &account)
KeyedAccount::new(key, false, account)
}
})
.collect();

View File

@ -28,7 +28,7 @@ fn main() {
};
let mut out = BufWriter::new(file);
let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
for caps in sysc_re.captures_iter(&text) {
for caps in sysc_re.captures_iter(text) {
writeln!(out, "{}", caps[1].to_string()).unwrap();
}
}

View File

@ -128,7 +128,7 @@ fn write_program_data(
);
return Err(InstructionError::AccountDataTooSmall);
}
data[program_data_offset..program_data_offset + len].copy_from_slice(&bytes);
data[program_data_offset..program_data_offset + len].copy_from_slice(bytes);
Ok(())
}
@ -369,7 +369,7 @@ fn process_loader_upgradeable_instruction(
// Create ProgramData account
let (derived_address, bump_seed) =
Pubkey::find_program_address(&[program.unsigned_key().as_ref()], &program_id);
Pubkey::find_program_address(&[program.unsigned_key().as_ref()], program_id);
if derived_address != *programdata.unsigned_key() {
ic_logger_msg!(logger, "ProgramData address is not derived");
return Err(InstructionError::InvalidArgument);
@ -759,7 +759,7 @@ impl Executor for BpfExecutor {
let mut serialize_time = Measure::start("serialize");
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let mut parameter_bytes =
serialize_parameters(loader_id, program_id, keyed_accounts, &instruction_data)?;
serialize_parameters(loader_id, program_id, keyed_accounts, instruction_data)?;
serialize_time.stop();
let mut create_vm_time = Measure::start("create_vm");
let mut execute_time;
@ -2228,7 +2228,7 @@ mod tests {
.unwrap();
buffer_account.borrow_mut().data_as_mut_slice()
[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
.copy_from_slice(&elf_new);
.copy_from_slice(elf_new);
let programdata_account = AccountSharedData::new_ref(
min_programdata_balance,
UpgradeableLoaderState::programdata_len(elf_orig.len().max(elf_new.len())).unwrap(),

View File

@ -104,7 +104,7 @@ pub fn serialize_parameters_unaligned(
.map_err(|_| InstructionError::InvalidArgument)?;
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
.map_err(|_| InstructionError::InvalidArgument)?;
v.write_all(&keyed_account.try_account_ref()?.data())
v.write_all(keyed_account.try_account_ref()?.data())
.map_err(|_| InstructionError::InvalidArgument)?;
v.write_all(keyed_account.owner()?.as_ref())
.map_err(|_| InstructionError::InvalidArgument)?;
@ -223,7 +223,7 @@ pub fn serialize_parameters_aligned(
.map_err(|_| InstructionError::InvalidArgument)?;
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
.map_err(|_| InstructionError::InvalidArgument)?;
v.write_all(&keyed_account.try_account_ref()?.data())
v.write_all(keyed_account.try_account_ref()?.data())
.map_err(|_| InstructionError::InvalidArgument)?;
v.resize(
MAX_PERMITTED_DATA_INCREASE
@ -382,9 +382,9 @@ mod tests {
.enumerate()
.map(|(i, (key, account))| {
if i <= accounts.len() / 2 {
KeyedAccount::new_readonly(&key, false, &account)
KeyedAccount::new_readonly(key, false, account)
} else {
KeyedAccount::new(&key, false, &account)
KeyedAccount::new(key, false, account)
}
})
.collect();
@ -439,9 +439,9 @@ mod tests {
.enumerate()
.map(|(i, (key, account))| {
if i <= accounts.len() / 2 {
KeyedAccount::new_readonly(&key, false, &account)
KeyedAccount::new_readonly(key, false, account)
} else {
KeyedAccount::new(&key, false, &account)
KeyedAccount::new(key, false, account)
}
})
.collect();
@ -487,9 +487,9 @@ mod tests {
.enumerate()
.map(|(i, (key, account))| {
if i < accounts.len() / 2 {
KeyedAccount::new_readonly(&key, false, &account)
KeyedAccount::new_readonly(key, false, account)
} else {
KeyedAccount::new(&key, false, &account)
KeyedAccount::new(key, false, account)
}
})
.collect();

View File

@ -597,7 +597,7 @@ impl<'a> SyscallObject<BpfError> for SyscallPanic<'a> {
memory_mapping,
file,
len,
&self.loader_id,
self.loader_id,
self.enforce_aligned_host_addrs,
&mut |string: &str| Err(SyscallError::Panic(string.to_string(), line, column).into()),
);
@ -628,7 +628,7 @@ impl<'a> SyscallObject<BpfError> for SyscallLog<'a> {
memory_mapping,
addr,
len,
&self.loader_id,
self.loader_id,
self.enforce_aligned_host_addrs,
&mut |string: &str| {
stable_log::program_log(&self.logger, string);
@ -2051,7 +2051,7 @@ where
let mut accounts = Vec::with_capacity(account_keys.len());
let mut refs = Vec::with_capacity(account_keys.len());
for (i, ref account_key) in account_keys.iter().enumerate() {
let account = invoke_context.get_account(&account_key).ok_or_else(|| {
let account = invoke_context.get_account(account_key).ok_or_else(|| {
ic_msg!(
invoke_context,
"Instruction references an unknown account {}",
@ -2215,7 +2215,7 @@ fn call<'a>(
let instruction = syscall.translate_instruction(
instruction_addr,
&memory_mapping,
memory_mapping,
enforce_aligned_host_addrs,
)?;
let signers = syscall.translate_signers(

View File

@ -30,7 +30,7 @@ pub fn process_instruction(
return Err(InstructionError::InvalidAccountOwner);
}
deserialize(&config_account.data()).map_err(|err| {
deserialize(config_account.data()).map_err(|err| {
ic_msg!(
invoke_context,
"Unable to deserialize config account: {}",
@ -130,7 +130,7 @@ pub fn process_instruction(
config_keyed_account
.try_account_ref_mut()?
.data_as_mut_slice()[..data.len()]
.copy_from_slice(&data);
.copy_from_slice(data);
Ok(())
}
@ -216,7 +216,7 @@ mod tests {
let (_, config_account) = create_config_account(keys);
assert_eq!(
Some(MyConfig::default()),
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
deserialize(get_config_data(config_account.borrow().data()).unwrap()).ok()
);
}
@ -241,7 +241,7 @@ mod tests {
);
assert_eq!(
Some(my_config),
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
deserialize(get_config_data(config_account.borrow().data()).unwrap()).ok()
);
}
@ -321,11 +321,11 @@ mod tests {
),
Ok(())
);
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
let meta_data: ConfigKeys = deserialize(config_account.borrow().data()).unwrap();
assert_eq!(meta_data.keys, keys);
assert_eq!(
Some(my_config),
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
deserialize(get_config_data(config_account.borrow().data()).unwrap()).ok()
);
}
@ -454,11 +454,11 @@ mod tests {
),
Ok(())
);
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
let meta_data: ConfigKeys = deserialize(config_account.borrow().data()).unwrap();
assert_eq!(meta_data.keys, keys);
assert_eq!(
new_config,
MyConfig::deserialize(get_config_data(&config_account.borrow().data()).unwrap())
MyConfig::deserialize(get_config_data(config_account.borrow().data()).unwrap())
.unwrap()
);
@ -646,11 +646,11 @@ mod tests {
),
Ok(())
);
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
let meta_data: ConfigKeys = deserialize(config_account.borrow().data()).unwrap();
assert_eq!(meta_data.keys, keys);
assert_eq!(
new_config,
MyConfig::deserialize(get_config_data(&config_account.borrow().data()).unwrap())
MyConfig::deserialize(get_config_data(config_account.borrow().data()).unwrap())
.unwrap()
);

View File

@ -54,5 +54,5 @@ pub fn create_account(
/// transaction containing this instruction.
pub fn store(date_pubkey: &Pubkey, date: Date<Utc>) -> Instruction {
let date_config = DateConfig::new(date);
config_instruction::store(&date_pubkey, true, vec![], &date_config)
config_instruction::store(date_pubkey, true, vec![], &date_config)
}

View File

@ -193,11 +193,11 @@ impl ExchangeProcessor {
error!("Not enough accounts");
return Err(InstructionError::InvalidArgument);
}
Self::is_account_unallocated(&keyed_accounts[NEW_ACCOUNT_INDEX].try_account_ref()?.data())?;
Self::is_account_unallocated(keyed_accounts[NEW_ACCOUNT_INDEX].try_account_ref()?.data())?;
Self::serialize(
&ExchangeState::Account(
TokenAccountInfo::default()
.owner(&keyed_accounts[OWNER_INDEX].unsigned_key())
.owner(keyed_accounts[OWNER_INDEX].unsigned_key())
.tokens(100_000, 100_000, 100_000, 100_000),
),
&mut keyed_accounts[NEW_ACCOUNT_INDEX]
@ -221,13 +221,13 @@ impl ExchangeProcessor {
}
let mut to_account =
Self::deserialize_account(&keyed_accounts[TO_ACCOUNT_INDEX].try_account_ref()?.data())?;
Self::deserialize_account(keyed_accounts[TO_ACCOUNT_INDEX].try_account_ref()?.data())?;
if &faucet::id() == keyed_accounts[FROM_ACCOUNT_INDEX].unsigned_key() {
to_account.tokens[token] += tokens;
} else {
let state: ExchangeState =
bincode::deserialize(&keyed_accounts[FROM_ACCOUNT_INDEX].try_account_ref()?.data())
bincode::deserialize(keyed_accounts[FROM_ACCOUNT_INDEX].try_account_ref()?.data())
.map_err(Self::map_to_invalid_arg)?;
match state {
ExchangeState::Account(mut from_account) => {
@ -309,10 +309,10 @@ impl ExchangeProcessor {
return Err(InstructionError::InvalidArgument);
}
Self::is_account_unallocated(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
Self::is_account_unallocated(keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
let mut account = Self::deserialize_account(
&keyed_accounts[ACCOUNT_INDEX].try_account_ref_mut()?.data(),
keyed_accounts[ACCOUNT_INDEX].try_account_ref_mut()?.data(),
)?;
if &account.owner != keyed_accounts[OWNER_INDEX].unsigned_key() {
@ -368,7 +368,7 @@ impl ExchangeProcessor {
}
let order =
Self::deserialize_order(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
Self::deserialize_order(keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
if &order.owner != keyed_accounts[OWNER_INDEX].unsigned_key() {
error!("Signer does not own order");
@ -404,11 +404,11 @@ impl ExchangeProcessor {
}
let mut to_order =
Self::deserialize_order(&keyed_accounts[TO_ORDER_INDEX].try_account_ref()?.data())?;
Self::deserialize_order(keyed_accounts[TO_ORDER_INDEX].try_account_ref()?.data())?;
let mut from_order =
Self::deserialize_order(&keyed_accounts[FROM_ORDER_INDEX].try_account_ref()?.data())?;
Self::deserialize_order(keyed_accounts[FROM_ORDER_INDEX].try_account_ref()?.data())?;
let mut profit_account = Self::deserialize_account(
&keyed_accounts[PROFIT_ACCOUNT_INDEX]
keyed_accounts[PROFIT_ACCOUNT_INDEX]
.try_account_ref()?
.data(),
)?;
@ -639,7 +639,7 @@ mod test {
}
fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey {
let new = create_account(&client, &owner);
let new = create_account(client, owner);
let instruction = exchange_instruction::account_request(&owner.pubkey(), &new);
client
.send_and_confirm_instruction(owner, instruction)
@ -670,9 +670,9 @@ mod test {
trade_tokens: u64,
price: u64,
) -> (Pubkey, Pubkey) {
let trade = create_account(&client, &owner);
let src = create_token_account(&client, &owner);
transfer(&client, &owner, &src, from_token, src_tokens);
let trade = create_account(client, owner);
let src = create_token_account(client, owner);
transfer(client, owner, &src, from_token, src_tokens);
let instruction = exchange_instruction::trade_request(
&owner.pubkey(),

View File

@ -33,7 +33,7 @@ pub fn create_account(
let space = std::mem::size_of::<Pubkey>() as u64;
vec![
system_instruction::create_account(
&payer_pubkey,
payer_pubkey,
account_pubkey,
lamports,
space,

View File

@ -38,7 +38,7 @@ pub fn process_instruction(
let new_owner_pubkey: Pubkey = limited_deserialize(data)?;
let account_keyed_account = &mut keyed_account_at_index(keyed_accounts, 0)?;
let mut account_owner_pubkey: Pubkey =
limited_deserialize(&account_keyed_account.try_account_ref()?.data())?;
limited_deserialize(account_keyed_account.try_account_ref()?.data())?;
if account_owner_pubkey == Pubkey::default() {
account_owner_pubkey = new_owner_pubkey;
@ -47,7 +47,7 @@ pub fn process_instruction(
set_owner(
&mut account_owner_pubkey,
new_owner_pubkey,
&owner_keyed_account,
owner_keyed_account,
)?;
}

View File

@ -17,7 +17,7 @@ use solana_sdk::{
pub use solana_sdk::stake::config::*;
pub fn from<T: ReadableAccount>(account: &T) -> Option<Config> {
get_config_data(&account.data())
get_config_data(account.data())
.ok()
.and_then(|data| deserialize(data).ok())
}

View File

@ -91,7 +91,7 @@ pub fn process_instruction(
keyed_account_at_index(keyed_accounts, 3).map(|ka| ka.unsigned_key());
me.authorize_with_seed(
&authority_base,
authority_base,
&args.authority_seed,
&args.authority_owner,
&args.new_authorized_pubkey,
@ -102,7 +102,7 @@ pub fn process_instruction(
)
} else {
me.authorize_with_seed(
&authority_base,
authority_base,
&args.authority_seed,
&args.authority_owner,
&args.new_authorized_pubkey,
@ -119,7 +119,7 @@ pub fn process_instruction(
let vote = keyed_account_at_index(keyed_accounts, 1)?;
me.delegate(
&vote,
vote,
&from_keyed_account::<Clock>(keyed_account_at_index(keyed_accounts, 2)?)?,
&from_keyed_account::<StakeHistory>(keyed_account_at_index(keyed_accounts, 3)?)?,
&config::from_keyed_account(keyed_account_at_index(keyed_accounts, 4)?)?,

View File

@ -513,7 +513,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
}
self.authorize(
&signers,
&new_authority,
new_authority,
stake_authorize,
require_custodian_for_locked_stake_authorize,
clock,
@ -686,7 +686,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
split.set_state(&StakeState::Initialized(split_meta))?;
}
StakeState::Uninitialized => {
if !signers.contains(&self.unsigned_key()) {
if !signers.contains(self.unsigned_key()) {
return Err(InstructionError::MissingRequiredSignature);
}
}
@ -810,7 +810,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
(meta.lockup, reserve, false)
}
StakeState::Uninitialized => {
if !signers.contains(&self.unsigned_key()) {
if !signers.contains(self.unsigned_key()) {
return Err(InstructionError::MissingRequiredSignature);
}
(Lockup::default(), 0, false) // no lockup, no restrictions
@ -821,7 +821,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
// verify that lockup has expired or that the withdrawal is signed by
// the custodian, both epoch and unix_timestamp must have passed
let custodian_pubkey = custodian.and_then(|keyed_account| keyed_account.signer_key());
if lockup.is_in_force(&clock, custodian_pubkey) {
if lockup.is_in_force(clock, custodian_pubkey) {
return Err(StakeError::LockupInForce.into());
}
@ -3883,7 +3883,7 @@ mod tests {
fn test_authorize_with_seed() {
let base_pubkey = solana_sdk::pubkey::new_rand();
let seed = "42";
let withdrawer_pubkey = Pubkey::create_with_seed(&base_pubkey, &seed, &id()).unwrap();
let withdrawer_pubkey = Pubkey::create_with_seed(&base_pubkey, seed, &id()).unwrap();
let stake_lamports = 42;
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
@ -3904,7 +3904,7 @@ mod tests {
assert_eq!(
stake_keyed_account.authorize_with_seed(
&base_keyed_account,
&"",
"",
&id(),
&new_authority,
StakeAuthorize::Staker,
@ -3919,7 +3919,7 @@ mod tests {
assert_eq!(
stake_keyed_account.authorize_with_seed(
&stake_keyed_account,
&seed,
seed,
&id(),
&new_authority,
StakeAuthorize::Staker,
@ -3934,7 +3934,7 @@ mod tests {
assert_eq!(
stake_keyed_account.authorize_with_seed(
&base_keyed_account,
&seed,
seed,
&id(),
&new_authority,
StakeAuthorize::Staker,
@ -3949,7 +3949,7 @@ mod tests {
assert_eq!(
stake_keyed_account.authorize_with_seed(
&base_keyed_account,
&seed,
seed,
&id(),
&new_authority,
StakeAuthorize::Withdrawer,
@ -3964,7 +3964,7 @@ mod tests {
assert_eq!(
stake_keyed_account.authorize_with_seed(
&stake_keyed_account,
&seed,
seed,
&id(),
&new_authority,
StakeAuthorize::Withdrawer,

View File

@ -230,7 +230,7 @@ impl VoteState {
// utility function, used by Stakes, tests
pub fn from<T: ReadableAccount>(account: &T) -> Option<VoteState> {
Self::deserialize(&account.data()).ok()
Self::deserialize(account.data()).ok()
}
// utility function, used by Stakes, tests
@ -239,7 +239,7 @@ impl VoteState {
}
pub fn deserialize(input: &[u8]) -> Result<Self, InstructionError> {
deserialize::<VoteStateVersions>(&input)
deserialize::<VoteStateVersions>(input)
.map(|versioned| versioned.convert_to_current())
.map_err(|_| InstructionError::InvalidAccountData)
}
@ -638,7 +638,7 @@ pub fn update_validator_identity<S: std::hash::BuildHasher>(
verify_authorized_signer(&vote_state.authorized_withdrawer, signers)?;
// new node must say "yay"
verify_authorized_signer(&node_pubkey, signers)?;
verify_authorized_signer(node_pubkey, signers)?;
vote_state.node_pubkey = *node_pubkey;
@ -938,7 +938,7 @@ mod tests {
slot_hashes: &[SlotHash],
epoch: Epoch,
) -> Result<VoteState, InstructionError> {
let keyed_accounts = &[KeyedAccount::new(&vote_pubkey, true, vote_account)];
let keyed_accounts = &[KeyedAccount::new(vote_pubkey, true, vote_account)];
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
process_vote(
&keyed_accounts[0],

View File

@ -19,7 +19,7 @@ pub fn parse_vote_transaction(tx: &Transaction) -> Option<(Pubkey, Vote, Option<
let prog_id_idx = first_instruction.program_id_index as usize;
match message.account_keys.get(prog_id_idx) {
Some(program_id) => {
if !crate::check_id(&program_id) {
if !crate::check_id(program_id) {
return None;
}
}