Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Avoid using ok_or with allocated argument #7357

Merged
merged 1 commit into from
Dec 22, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/src/engines/validator_set/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl ValidatorContract {
let client = self.client.read().clone();
Box::new(move |a, d| client.as_ref()
.and_then(Weak::upgrade)
.ok_or("No client!".into())
.ok_or_else(|| "No client!".into())
.and_then(|c| {
match c.as_full_client() {
Some(c) => c.transact_contract(a, d)
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/validator_set/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl ValidatorSet for Multi {
}
*self.block_number.write() = Box::new(move |id| client
.upgrade()
.ok_or("No client!".into())
.ok_or_else(|| "No client!".into())
.and_then(|c| c.block_number(id).ok_or("Unknown block".into())));
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ValidatorSet for ValidatorSafeContract {
let client = self.client.read().clone();
Box::new(move |addr, data| client.as_ref()
.and_then(Weak::upgrade)
.ok_or("No client!".into())
.ok_or_else(|| "No client!".into())
.and_then(|c| {
match c.as_full_client() {
Some(c) => c.call_contract(id, addr, data),
Expand Down
2 changes: 1 addition & 1 deletion parity/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod server {
// Attempt to sign in the engine signer.
let password = deps.accounts_passwords.iter()
.find(|p| deps.account_provider.sign(account.clone(), Some((*p).clone()), Default::default()).is_ok())
.ok_or(format!("No valid password for the secret store node account {}", account))?;
.ok_or_else(|| format!("No valid password for the secret store node account {}", account))?;
Arc::new(ethcore_secretstore::KeyStoreNodeKeyPair::new(deps.account_provider, account, password.clone())
.map_err(|e| format!("{}", e))?)
},
Expand Down
2 changes: 1 addition & 1 deletion secret_store/src/acl_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl CachedContract {
let do_call = |a, d| future::done(
self.client
.upgrade()
.ok_or("Calling contract without client".into())
.ok_or_else(|| "Calling contract without client".into())
.and_then(|c| c.call_contract(BlockId::Latest, a, d)));
contract.check_permissions(do_call, address, document.clone())
.map_err(|err| Error::Internal(err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<T> SessionImpl<T> where T: SessionTransport {
let admin_public = self.core.admin_public.as_ref().cloned().ok_or(Error::ConsensusUnreachable)?;

// key share version is required on ShareAdd master node
let key_share = self.core.key_share.as_ref().ok_or(Error::KeyStorage("key share is not found on master node".into()))?;
let key_share = self.core.key_share.as_ref().ok_or_else(|| Error::KeyStorage("key share is not found on master node".into()))?;
let key_version = key_share.version(&version).map_err(|e| Error::KeyStorage(e.into()))?;

// old nodes set is all non-isolated owners of version holders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<T> SessionImpl<T> where T: SessionTransport {
let is_consensus_pre_established = data.shares_to_move.is_some();
if !is_consensus_pre_established {
let shares_to_move_reversed = shares_to_move_reversed.ok_or(Error::InvalidMessage)?;
let key_share = self.core.key_share.as_ref().ok_or(Error::KeyStorage("key share is not found on master node".into()))?;
let key_share = self.core.key_share.as_ref().ok_or_else(|| Error::KeyStorage("key share is not found on master node".into()))?;
check_shares_to_move(&self.core.meta.self_node_id, &shares_to_move_reversed, Some(&key_share.id_numbers))?;

let old_set_signature = old_set_signature.ok_or(Error::InvalidMessage)?;
Expand Down Expand Up @@ -424,7 +424,7 @@ impl<T> SessionImpl<T> where T: SessionTransport {
if !move_confirmations_to_receive.remove(sender) {
return Err(Error::InvalidMessage);
}

if !move_confirmations_to_receive.is_empty() {
return Ok(());
}
Expand Down Expand Up @@ -818,7 +818,7 @@ mod tests {

// check that session has completed on all nodes
assert!(ml.nodes.values().all(|n| n.session.is_finished()));

// check that secret is still the same as before adding the share
check_secret_is_preserved(ml.original_key_pair.clone(), ml.nodes.iter()
.filter(|&(k, _)| !shares_to_move.values().any(|v| v == k))
Expand Down
2 changes: 1 addition & 1 deletion secret_store/src/key_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl PersistentKeyStorage {
pub fn new(config: &ServiceConfiguration) -> Result<Self, Error> {
let mut db_path = PathBuf::from(&config.data_path);
db_path.push("db");
let db_path = db_path.to_str().ok_or(Error::Database("Invalid secretstore path".to_owned()))?;
let db_path = db_path.to_str().ok_or_else(|| Error::Database("Invalid secretstore path".to_owned()))?;

let db = Database::open_default(&db_path)?;
let db = upgrade_db(db)?;
Expand Down