Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: appease clippy and fmt after new Rust release #899

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/crates/soroban-spec-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn generate_from_wasm(wasm: &[u8]) -> Result<String, FromWasmError> {
Ok(json)
}

/// # Panics
pub fn generate(spec: &[ScSpecEntry]) -> String {
let collected: Vec<_> = spec.iter().map(Entry::from).collect();
serde_json::to_string_pretty(&collected).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived")
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result<clap::Command, Error> {
let long_doc: &'static str = Box::leak(arg_file_help(doc).into_boxed_str());

cmd = cmd.about(Some(doc)).long_about(long_doc);
for (name, type_) in inputs_map.iter() {
for (name, type_) in inputs_map {
let mut arg = clap::Arg::new(name);
let file_arg_name = fmt_arg_file_name(name);
let mut file_arg = clap::Arg::new(&file_arg_name);
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn short() -> String {
pub fn long() -> String {
let env = soroban_env_host::VERSION;
let xdr = soroban_env_host::VERSION.xdr;
vec![
[
short(),
format!("soroban-env {} ({})", env.pkg, env.rev),
format!("soroban-env interface version {}", meta::INTERFACE_VERSION),
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/log/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use soroban_env_host::events::HostEvent;

pub fn events(events: &[HostEvent]) {
for event in events.iter() {
for event in events {
tracing::info!(log = event.to_string());
}
}
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/rpc/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ pub fn sign_soroban_authorizations(
let SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(ref mut credentials),
..
} = auth else {
} = auth
else {
// Doesn't need special signing
return Ok(auth);
};
Expand Down Expand Up @@ -184,7 +185,8 @@ pub fn sign_soroban_authorization_entry(
let SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(ref mut credentials),
..
} = auth else {
} = auth
else {
// Doesn't need special signing
return Ok(auth);
};
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn add_contract_code_to_ledger_entries(
}),
ext: LedgerEntryExt::V0,
};
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if **k == code_key {
**e = code_entry;
return Ok(hash);
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn add_contract_to_ledger_entries(
}),
ext: LedgerEntryExt::V0,
};
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if **k == contract_key {
**e = contract_entry;
return;
Expand All @@ -138,7 +138,7 @@ pub fn bump_ledger_entry_expirations<S: BuildHasher>(
entries: &mut [(Box<LedgerKey>, Box<LedgerEntry>)],
lookup: &HashMap<LedgerKey, u32, S>,
) {
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if let Some(min_expiration) = lookup.get(k.as_ref()) {
if let LedgerEntryData::ContractData(entry) = &mut e.data {
entry.expiration_ledger_seq = *min_expiration;
Expand Down
13 changes: 6 additions & 7 deletions cmd/soroban-rpc/lib/preflight/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ fn get_fee_configurations(
ledger_storage.get_configuration_setting(ConfigSettingId::ContractComputeV0)?
else {
bail!("unexpected config setting entry for ComputeV0 key");

};

let ConfigSettingEntry::ContractLedgerCostV0(ledger_cost) =
Expand Down Expand Up @@ -195,9 +194,9 @@ fn get_fee_configurations(

let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(ConfigSettingId::StateExpiration)?
else {
bail!("unexpected config setting entry for StateExpiration key");
};
else {
bail!("unexpected config setting entry for StateExpiration key");
};

let write_fee_configuration = WriteFeeConfiguration {
bucket_list_target_size_bytes: ledger_cost.bucket_list_target_size_bytes,
Expand Down Expand Up @@ -395,9 +394,9 @@ pub(crate) fn compute_restore_footprint_transaction_data_and_min_fee(
) -> Result<(SorobanTransactionData, i64)> {
let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(ConfigSettingId::StateExpiration)?
else {
bail!("unexpected config setting entry for StateExpiration key");
};
else {
bail!("unexpected config setting entry for StateExpiration key");
};
let rent_changes = compute_restore_footprint_rent_changes(
&footprint,
ledger_storage,
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ impl LedgerStorage {
let setting_id = ConfigSettingId::StateExpiration;
let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(setting_id)?
else {
return Err(
Error::UnexpectedConfigLedgerEntry { setting_id: setting_id.name().to_string() }
);
};
else {
return Err(Error::UnexpectedConfigLedgerEntry {
setting_id: setting_id.name().to_string(),
});
};
// Now that we have the state expiration config, we can build the tracker
ledger_storage.restore_tracker = Some(EntryRestoreTracker {
current_ledger_seq: current_ledger_sequence,
Expand Down
18 changes: 9 additions & 9 deletions cmd/soroban-rpc/lib/preflight/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,21 @@ fn host_events_to_diagnostic_events(events: &Events) -> Vec<DiagnosticEvent> {
fn get_budget_from_network_config_params(ledger_storage: &LedgerStorage) -> Result<Budget> {
let ConfigSettingEntry::ContractComputeV0(compute) =
ledger_storage.get_configuration_setting(ConfigSettingId::ContractComputeV0)?
else {
bail!("unexpected config setting entry for ComputeV0 key");
};
else {
bail!("unexpected config setting entry for ComputeV0 key");
};

let ConfigSettingEntry::ContractCostParamsCpuInstructions(cost_params_cpu) = ledger_storage
.get_configuration_setting(ConfigSettingId::ContractCostParamsCpuInstructions)?
else {
bail!("unexpected config setting entry for CostParamsCpuInstructions key");
};
else {
bail!("unexpected config setting entry for CostParamsCpuInstructions key");
};

let ConfigSettingEntry::ContractCostParamsMemoryBytes(cost_params_memory) =
ledger_storage.get_configuration_setting(ConfigSettingId::ContractCostParamsMemoryBytes)?
else {
bail!("unexpected config setting entry for CostParamsMemoryBytes key");
};
else {
bail!("unexpected config setting entry for CostParamsMemoryBytes key");
};

let budget = Budget::try_from_configs(
compute.tx_max_instructions as u64,
Expand Down