Enable clippy's or_fun_call linter (#7222)

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
This commit is contained in:
Justin Traglia
2024-03-19 10:52:41 -05:00
committed by GitHub
parent 553a271533
commit 11bedc1884
14 changed files with 19 additions and 19 deletions

View File

@ -93,6 +93,7 @@ clippy.redundant_clone = "deny"
clippy.trait_duplication_in_bounds = "deny" clippy.trait_duplication_in_bounds = "deny"
clippy.uninlined_format_args = "deny" clippy.uninlined_format_args = "deny"
clippy.equatable_if_let = "deny" clippy.equatable_if_let = "deny"
clippy.or_fun_call = "deny"
[workspace.package] [workspace.package]
version = "0.2.0-beta.3" version = "0.2.0-beta.3"

View File

@ -79,7 +79,7 @@ impl ImportCommand {
// add network name to data dir // add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain); let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let config_path = self.config.clone().unwrap_or(data_dir.config_path()); let config_path = self.config.clone().unwrap_or_else(|| data_dir.config_path());
let config: Config = self.load_config(config_path.clone())?; let config: Config = self.load_config(config_path.clone())?;
info!(target: "reth::cli", path = ?config_path, "Configuration loaded"); info!(target: "reth::cli", path = ?config_path, "Configuration loaded");

View File

@ -286,14 +286,14 @@ mod tests {
NodeCommand::try_parse_args_from(["reth", "--config", "my/path/to/reth.toml"]).unwrap(); NodeCommand::try_parse_args_from(["reth", "--config", "my/path/to/reth.toml"]).unwrap();
// always store reth.toml in the data dir, not the chain specific data dir // always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain); let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let config_path = cmd.config.unwrap_or(data_dir.config_path()); let config_path = cmd.config.unwrap_or_else(|| data_dir.config_path());
assert_eq!(config_path, Path::new("my/path/to/reth.toml")); assert_eq!(config_path, Path::new("my/path/to/reth.toml"));
let cmd = NodeCommand::try_parse_args_from(["reth"]).unwrap(); let cmd = NodeCommand::try_parse_args_from(["reth"]).unwrap();
// always store reth.toml in the data dir, not the chain specific data dir // always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain); let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let config_path = cmd.config.clone().unwrap_or(data_dir.config_path()); let config_path = cmd.config.clone().unwrap_or_else(|| data_dir.config_path());
let end = format!("reth/{}/reth.toml", SUPPORTED_CHAINS[0]); let end = format!("reth/{}/reth.toml", SUPPORTED_CHAINS[0]);
assert!(config_path.ends_with(end), "{:?}", cmd.config); assert!(config_path.ends_with(end), "{:?}", cmd.config);
} }

View File

@ -104,7 +104,7 @@ impl Command {
// add network name to data dir // add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain); let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let config_path = self.config.clone().unwrap_or(data_dir.config_path()); let config_path = self.config.clone().unwrap_or_else(|| data_dir.config_path());
let mut config: Config = confy::load_path(&config_path).unwrap_or_default(); let mut config: Config = confy::load_path(&config_path).unwrap_or_default();

View File

@ -126,7 +126,7 @@ impl Command {
// add network name to data dir // add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain); let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let config_path = self.config.clone().unwrap_or(data_dir.config_path()); let config_path = self.config.clone().unwrap_or_else(|| data_dir.config_path());
let config: Config = confy::load_path(config_path).unwrap_or_default(); let config: Config = confy::load_path(config_path).unwrap_or_default();
info!(target: "reth::cli", "reth {} starting stage {:?}", SHORT_VERSION, self.stage); info!(target: "reth::cli", "reth {} starting stage {:?}", SHORT_VERSION, self.stage);

View File

@ -251,7 +251,7 @@ where
} }
old old
}; };
Some(StorageEntry { value: old.unwrap_or(U256::from(0)), ..entry }) Some(StorageEntry { value: old.unwrap_or(U256::ZERO), ..entry })
}) })
.collect(); .collect();
old_entries.sort_by_key(|entry| entry.key); old_entries.sort_by_key(|entry| entry.key);

View File

@ -503,7 +503,7 @@ impl NetworkConfigBuilder {
peers_config: peers_config.unwrap_or_default(), peers_config: peers_config.unwrap_or_default(),
sessions_config: sessions_config.unwrap_or_default(), sessions_config: sessions_config.unwrap_or_default(),
chain_spec, chain_spec,
block_import: block_import.unwrap_or(Box::<ProofOfStakeBlockImport>::default()), block_import: block_import.unwrap_or_else(|| Box::<ProofOfStakeBlockImport>::default()),
network_mode, network_mode,
executor: executor.unwrap_or_else(|| Box::<TokioTaskExecutor>::default()), executor: executor.unwrap_or_else(|| Box::<TokioTaskExecutor>::default()),
status, status,

View File

@ -470,7 +470,7 @@ where
let sync_metrics_listener = reth_stages::MetricsListener::new(sync_metrics_rx); let sync_metrics_listener = reth_stages::MetricsListener::new(sync_metrics_rx);
executor.spawn_critical("stages metrics listener task", sync_metrics_listener); executor.spawn_critical("stages metrics listener task", sync_metrics_listener);
let prune_config = config.prune_config()?.or(reth_config.prune.clone()); let prune_config = config.prune_config()?.or_else(|| reth_config.prune.clone());
let evm_config = types.evm_config(); let evm_config = types.evm_config();
let tree_config = BlockchainTreeConfig::default(); let tree_config = BlockchainTreeConfig::default();

View File

@ -276,7 +276,7 @@ mod builder {
let mut cumulative_gas_used = 0; let mut cumulative_gas_used = 0;
let block_gas_limit: u64 = attributes let block_gas_limit: u64 = attributes
.gas_limit .gas_limit
.unwrap_or(initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX)); .unwrap_or_else(|| initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX));
let base_fee = initialized_block_env.basefee.to::<u64>(); let base_fee = initialized_block_env.basefee.to::<u64>();
let mut executed_txs = Vec::new(); let mut executed_txs = Vec::new();

View File

@ -355,7 +355,7 @@ pub(crate) fn create_txn_env(
block_env.get_blob_gasprice().map(U256::from), block_env.get_blob_gasprice().map(U256::from),
)?; )?;
let gas_limit = gas.unwrap_or(block_env.gas_limit.min(U256::from(u64::MAX))); let gas_limit = gas.unwrap_or_else(|| block_env.gas_limit.min(U256::from(u64::MAX)));
let env = TxEnv { let env = TxEnv {
gas_limit: gas_limit.try_into().map_err(|_| RpcInvalidTransactionError::GasUintOverflow)?, gas_limit: gas_limit.try_into().map_err(|_| RpcInvalidTransactionError::GasUintOverflow)?,
nonce: nonce nonce: nonce

View File

@ -241,7 +241,7 @@ mod tests {
let server = spawn_server().await; let server = spawn_server().await;
let client = hyper::Client::new(); let client = hyper::Client::new();
let jwt = jwt.unwrap_or("".into()); let jwt = jwt.unwrap_or_default();
let address = format!("http://{AUTH_ADDR}:{AUTH_PORT}"); let address = format!("http://{AUTH_ADDR}:{AUTH_PORT}");
let bearer = format!("Bearer {jwt}"); let bearer = format!("Bearer {jwt}");
let body = r#"{"jsonrpc": "2.0", "method": "greet_melkor", "params": [], "id": 1}"#; let body = r#"{"jsonrpc": "2.0", "method": "greet_melkor", "params": [], "id": 1}"#;

View File

@ -237,7 +237,7 @@ impl StaticFileProviderRW {
.user_header() .user_header()
.block_end() .block_end()
.map(|b| b + 1) .map(|b| b + 1)
.unwrap_or(self.writer.user_header().expected_block_start()); .unwrap_or_else(|| self.writer.user_header().expected_block_start());
if expected_block_number != next_static_file_block { if expected_block_number != next_static_file_block {
return Err(ProviderError::UnexpectedStaticFileBlockNumber( return Err(ProviderError::UnexpectedStaticFileBlockNumber(

View File

@ -51,11 +51,10 @@ impl LogFormat {
let target = std::env::var("RUST_LOG_TARGET") let target = std::env::var("RUST_LOG_TARGET")
// `RUST_LOG_TARGET` always overrides default behaviour // `RUST_LOG_TARGET` always overrides default behaviour
.map(|val| val != "0") .map(|val| val != "0")
.unwrap_or( .unwrap_or_else(|_|
// If `RUST_LOG_TARGET` is not set, show target in logs only if the max enabled // If `RUST_LOG_TARGET` is not set, show target in logs only if the max enabled
// level is higher than INFO (DEBUG, TRACE) // level is higher than INFO (DEBUG, TRACE)
filter.max_level_hint().map_or(true, |max_level| max_level > tracing::Level::INFO), filter.max_level_hint().map_or(true, |max_level| max_level > tracing::Level::INFO));
);
match self { match self {
LogFormat::Json => { LogFormat::Json => {

View File

@ -232,9 +232,9 @@ impl<'b, C> HashedPostStateStorageCursor<'b, C> {
} }
} }
// Return either non-empty entry // Return either non-empty entry
_ => { _ => db_item.or_else(|| {
db_item.or(post_state_item.copied().map(|(key, value)| StorageEntry { key, value })) post_state_item.copied().map(|(key, value)| StorageEntry { key, value })
} }),
} }
} }
} }