Fix Nightly Clippy Warnings (backport #18065) (#18070)

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

(cherry picked from commit 6514096a67)

# Conflicts:
#	core/src/banking_stage.rs
#	core/src/cost_model.rs
#	core/src/cost_tracker.rs
#	core/src/execute_cost_table.rs
#	core/src/replay_stage.rs
#	core/src/tvu.rs
#	ledger-tool/src/main.rs
#	programs/bpf_loader/build.rs
#	rbpf-cli/src/main.rs
#	sdk/cargo-build-bpf/src/main.rs
#	sdk/cargo-test-bpf/src/main.rs
#	sdk/src/secp256k1_instruction.rs

* chore: cargo fmt

(cherry picked from commit 789f33e8db)

* Updates BPF program assert_instruction_count tests.

(cherry picked from commit c1e03f3410)

# Conflicts:
#	programs/bpf/tests/programs.rs

* Resolve conflicts

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2021-06-18 20:02:48 +00:00
committed by GitHub
parent c330016109
commit 0e7512a225
173 changed files with 1250 additions and 1056 deletions

View File

@@ -112,7 +112,7 @@ fn install_if_missing(
url.push_str(version);
url.push('/');
url.push_str(file.to_str().unwrap());
download_file(&url.as_str(), &file, true, &mut None)?;
download_file(url.as_str(), file, true, &mut None)?;
fs::create_dir_all(&target_path).map_err(|err| err.to_string())?;
let zip = File::open(&file).map_err(|err| err.to_string())?;
let tar = BzDecoder::new(BufReader::new(zip));
@@ -423,14 +423,14 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
"solana-bpf-tools-linux.tar.bz2"
};
install_if_missing(
&config,
config,
"bpf-tools",
"v1.8",
"https://github.com/solana-labs/bpf-tools/releases/download",
&PathBuf::from(bpf_tools_filename),
)
.expect("Failed to install bpf-tools");
link_bpf_toolchain(&config);
link_bpf_toolchain(config);
let llvm_bin = config
.bpf_sdk
@@ -522,7 +522,7 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
postprocess_dump(&program_dump);
}
check_undefined_symbols(&config, &program_so);
check_undefined_symbols(config, &program_so);
println!();
println!("To deploy this program:");

View File

@@ -122,7 +122,7 @@ fn test_bpf_package(config: &Config, target_directory: &Path, package: &cargo_me
cargo_args.push("test-bpf");
}
for extra_cargo_test_arg in &config.extra_cargo_test_args {
cargo_args.push(&extra_cargo_test_arg);
cargo_args.push(extra_cargo_test_arg);
}
spawn(&config.cargo, &cargo_args);
}

View File

@@ -308,10 +308,8 @@ impl Message {
nonce_account_pubkey: &Pubkey,
nonce_authority_pubkey: &Pubkey,
) -> Self {
let nonce_ix = system_instruction::advance_nonce_account(
&nonce_account_pubkey,
&nonce_authority_pubkey,
);
let nonce_ix =
system_instruction::advance_nonce_account(nonce_account_pubkey, nonce_authority_pubkey);
instructions.insert(0, nonce_ix);
Self::new(&instructions, payer)
}
@@ -482,20 +480,20 @@ impl Message {
data: &[u8],
) -> Result<Instruction, SanitizeError> {
let mut current = 0;
let num_instructions = read_u16(&mut current, &data)?;
let num_instructions = read_u16(&mut current, data)?;
if index >= num_instructions as usize {
return Err(SanitizeError::IndexOutOfBounds);
}
// index into the instruction byte-offset table.
current += index * 2;
let start = read_u16(&mut current, &data)?;
let start = read_u16(&mut current, data)?;
current = start as usize;
let num_accounts = read_u16(&mut current, &data)?;
let num_accounts = read_u16(&mut current, data)?;
let mut accounts = Vec::with_capacity(num_accounts as usize);
for _ in 0..num_accounts {
let meta_byte = read_u8(&mut current, &data)?;
let meta_byte = read_u8(&mut current, data)?;
let mut is_signer = false;
let mut is_writable = false;
if meta_byte & (1 << Self::IS_SIGNER_BIT) != 0 {
@@ -504,16 +502,16 @@ impl Message {
if meta_byte & (1 << Self::IS_WRITABLE_BIT) != 0 {
is_writable = true;
}
let pubkey = read_pubkey(&mut current, &data)?;
let pubkey = read_pubkey(&mut current, data)?;
accounts.push(AccountMeta {
pubkey,
is_signer,
is_writable,
});
}
let program_id = read_pubkey(&mut current, &data)?;
let data_len = read_u16(&mut current, &data)?;
let data = read_slice(&mut current, &data, data_len as usize)?;
let program_id = read_pubkey(&mut current, data)?;
let data_len = read_u16(&mut current, data)?;
let data = read_slice(&mut current, data, data_len as usize)?;
Ok(Instruction {
program_id,
accounts,

View File

@@ -17,7 +17,7 @@ pub struct SlotHashes(Vec<SlotHash>);
impl SlotHashes {
pub fn add(&mut self, slot: Slot, hash: Hash) {
match self.binary_search_by(|(probe, _)| slot.cmp(&probe)) {
match self.binary_search_by(|(probe, _)| slot.cmp(probe)) {
Ok(index) => (self.0)[index] = (slot, hash),
Err(index) => (self.0).insert(index, (slot, hash)),
}
@@ -25,7 +25,7 @@ impl SlotHashes {
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn get(&self, slot: &Slot) -> Option<&Hash> {
self.binary_search_by(|(probe, _)| slot.cmp(&probe))
self.binary_search_by(|(probe, _)| slot.cmp(probe))
.ok()
.map(|index| &self[index].1)
}

View File

@@ -139,7 +139,7 @@ impl Authorized {
}
StakeAuthorize::Withdrawer => {
if let Some((lockup, clock, custodian)) = lockup_custodian_args {
if lockup.is_in_force(&clock, None) {
if lockup.is_in_force(clock, None) {
match custodian {
None => {
return Err(StakeError::CustodianMissing.into());
@@ -149,7 +149,7 @@ impl Authorized {
return Err(StakeError::CustodianSignatureMissing.into());
}
if lockup.is_in_force(&clock, Some(custodian)) {
if lockup.is_in_force(clock, Some(custodian)) {
return Err(StakeError::LockupInForce.into());
}
}

View File

@@ -588,7 +588,7 @@ pub mod tests {
use super::*;
fn make_two_accounts(key: &Pubkey) -> (Account, AccountSharedData) {
let mut account1 = Account::new(1, 2, &key);
let mut account1 = Account::new(1, 2, key);
account1.executable = true;
account1.rent_epoch = 4;
let mut account2 = AccountSharedData::new(1, 2, key);

View File

@@ -46,7 +46,7 @@ impl TryFrom<&str> for DerivationPath {
impl AsRef<[ChildIndex]> for DerivationPath {
fn as_ref(&self) -> &[ChildIndex] {
&self.0.as_ref()
self.0.as_ref()
}
}
@@ -88,7 +88,7 @@ impl DerivationPath {
}
fn _from_absolute_path_insecure_str(path: &str) -> Result<Self, DerivationPathError> {
Ok(Self(DerivationPathInner::from_str(&path).map_err(
Ok(Self(DerivationPathInner::from_str(path).map_err(
|err| DerivationPathError::InvalidDerivationPath(err.to_string()),
)?))
}

View File

@@ -160,7 +160,7 @@ impl GenesisConfig {
}
pub fn load(ledger_path: &Path) -> Result<Self, std::io::Error> {
let filename = Self::genesis_filename(&ledger_path);
let filename = Self::genesis_filename(ledger_path);
let file = OpenOptions::new()
.read(true)
.open(&filename)
@@ -198,7 +198,7 @@ impl GenesisConfig {
std::fs::create_dir_all(&ledger_path)?;
let mut file = File::create(Self::genesis_filename(&ledger_path))?;
let mut file = File::create(Self::genesis_filename(ledger_path))?;
file.write_all(&serialized)
}
@@ -339,8 +339,8 @@ mod tests {
&& account.lamports == 10_000));
let path = &make_tmp_path("genesis_config");
config.write(&path).expect("write");
let loaded_config = GenesisConfig::load(&path).expect("load");
config.write(path).expect("write");
let loaded_config = GenesisConfig::load(path).expect("load");
assert_eq!(config.hash(), loaded_config.hash());
let _ignored = std::fs::remove_file(&path);
}

View File

@@ -306,7 +306,7 @@ mod test {
let authorized = keyed_account.unsigned_key();
keyed_account
.initialize_nonce_account(
&authorized,
authorized,
&recent_blockhashes,
&rent,
&MockInvokeContext::new(vec![]),
@@ -367,7 +367,7 @@ mod test {
keyed_account
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -597,7 +597,7 @@ mod test {
nonce_keyed
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -639,7 +639,7 @@ mod test {
let lamports = nonce_keyed.account.borrow().lamports();
let result = nonce_keyed.withdraw_nonce_account(
lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -669,7 +669,7 @@ mod test {
let lamports = nonce_keyed.account.borrow().lamports() + 1;
let result = nonce_keyed.withdraw_nonce_account(
lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -699,7 +699,7 @@ mod test {
nonce_keyed
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -722,7 +722,7 @@ mod test {
nonce_keyed
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -779,7 +779,7 @@ mod test {
nonce_keyed
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -808,7 +808,7 @@ mod test {
nonce_keyed
.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -852,7 +852,7 @@ mod test {
let withdraw_lamports = nonce_keyed.account.borrow().lamports();
let result = nonce_keyed.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -888,7 +888,7 @@ mod test {
let withdraw_lamports = nonce_keyed.account.borrow().lamports() + 1;
let result = nonce_keyed.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -924,7 +924,7 @@ mod test {
let withdraw_lamports = nonce_keyed.account.borrow().lamports() - min_lamports + 1;
let result = nonce_keyed.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -960,7 +960,7 @@ mod test {
let withdraw_lamports = u64::MAX - 54;
let result = nonce_keyed.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
to_keyed,
&recent_blockhashes,
&rent,
&signers,
@@ -1149,7 +1149,7 @@ mod test {
let authorized = &Pubkey::default().clone();
nonce_account
.initialize_nonce_account(
&authorized,
authorized,
&recent_blockhashes,
&rent,
&MockInvokeContext::new(vec![]),
@@ -1176,7 +1176,7 @@ mod test {
let authorized = nonce_account.unsigned_key();
nonce_account
.initialize_nonce_account(
&authorized,
authorized,
&recent_blockhashes,
&Rent::free(),
&MockInvokeContext::new(vec![]),
@@ -1211,7 +1211,7 @@ mod test {
let authorized = nonce_account.unsigned_key();
nonce_account
.initialize_nonce_account(
&authorized,
authorized,
&recent_blockhashes,
&Rent::free(),
&MockInvokeContext::new(vec![]),

View File

@@ -140,7 +140,7 @@ pub fn verify_eth_addresses(
// Parse out pubkey
let eth_address_slice = get_data_slice(
&instruction_datas,
instruction_datas,
offsets.eth_address_instruction_index,
offsets.eth_address_offset,
HASHED_PUBKEY_SERIALIZED_SIZE,
@@ -148,7 +148,7 @@ pub fn verify_eth_addresses(
// Parse out message
let message_slice = get_data_slice(
&instruction_datas,
instruction_datas,
offsets.message_instruction_index,
offsets.message_data_offset,
offsets.message_data_size as usize,

View File

@@ -29,7 +29,7 @@ impl crate::sanitize::Sanitize for Signature {}
impl Signature {
pub fn new(signature_slice: &[u8]) -> Self {
Self(GenericArray::clone_from_slice(&signature_slice))
Self(GenericArray::clone_from_slice(signature_slice))
}
pub(self) fn verify_verbose(
@@ -54,7 +54,7 @@ pub trait Signable {
}
fn verify(&self) -> bool {
self.get_signature()
.verify(&self.pubkey().as_ref(), self.signable_data().borrow())
.verify(self.pubkey().as_ref(), self.signable_data().borrow())
}
fn pubkey(&self) -> Pubkey;

View File

@@ -459,7 +459,7 @@ pub fn uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstruction> {
.filter(|maybe_ix| {
let prog_id_idx = maybe_ix.program_id_index as usize;
match message.account_keys.get(prog_id_idx) {
Some(program_id) => system_program::check_id(&program_id),
Some(program_id) => system_program::check_id(program_id),
_ => false,
}
} && matches!(limited_deserialize(&maybe_ix.data), Ok(SystemInstruction::AdvanceNonceAccount))
@@ -968,7 +968,7 @@ mod tests {
let (_, nonce_pubkey, tx) = nonced_transfer_tx();
let nonce_ix = uses_durable_nonce(&tx).unwrap();
assert_eq!(
get_nonce_pubkey_from_instruction(&nonce_ix, &tx),
get_nonce_pubkey_from_instruction(nonce_ix, &tx),
Some(&nonce_pubkey),
);
}