Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1748 from holochain/clippy-fixes
Browse files Browse the repository at this point in the history
Another Clippy Party
  • Loading branch information
StaticallyTypedAnxiety committed Oct 9, 2019
2 parents dbc36b7 + 2219f2d commit 4d1633b
Show file tree
Hide file tree
Showing 29 changed files with 58 additions and 71 deletions.
20 changes: 11 additions & 9 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,19 @@ fn run() -> HolochainResult<()> {
};

let properties = properties_string
.map(|s| {
serde_json::Value::from_str(&s)
}).unwrap_or_else(|| {
Ok(json!({}))
});
.map(|s| serde_json::Value::from_str(&s))
.unwrap_or_else(|| Ok(json!({})));

match properties {
Ok(properties) => cli::package(strip_meta, output, properties).map_err(HolochainError::Default)?,
Err(e) => return Err(HolochainError::Default(format_err!(
"Failed to parse properties argument as JSON: {:?}", e
)))
Ok(properties) => {
cli::package(strip_meta, output, properties).map_err(HolochainError::Default)?
}
Err(e) => {
return Err(HolochainError::Default(format_err!(
"Failed to parse properties argument as JSON: {:?}",
e
)))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion conductor_api/src/context_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ContextBuilder {
eav_storage,
// TODO BLOCKER pass a peer list here?
self.p2p_config
.unwrap_or_else(|| P2pConfig::new_with_unique_memory_backend()),
.unwrap_or_else(P2pConfig::new_with_unique_memory_backend),
self.conductor_api,
self.signal_tx,
self.state_dump_logging,
Expand Down
6 changes: 3 additions & 3 deletions core/src/agent/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ChainStore {
"./*[]{}".chars().any(|y| y == c)
}
fn is_glob_str(s: &str) -> bool {
s.chars().any(|c| is_glob(c))
s.chars().any(is_glob)
}

// Unpack options; start == 0 --> start at beginning, limit == 0 --> take all remaining
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ChainStore {
ChainStoreQueryResult::Headers(
self.iter(start_chain_header)
.filter(|header| {
globset.matches(header.entry_type().to_string()).len() > 0
!globset.matches(header.entry_type().to_string()).is_empty()
})
.skip(start)
.take(limit)
Expand All @@ -173,7 +173,7 @@ impl ChainStore {
ChainStoreQueryResult::Addresses(
self.iter(start_chain_header)
.filter(|header| {
globset.matches(header.entry_type().to_string()).len() > 0
!globset.matches(header.entry_type().to_string()).is_empty()
})
.skip(start)
.take(limit)
Expand Down
2 changes: 1 addition & 1 deletion core/src/agent/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl From<&StateWrapper> for AgentStateSnapshot {
}
}

pub static AGENT_SNAPSHOT_ADDRESS: &'static str = "AgentState";
pub static AGENT_SNAPSHOT_ADDRESS: &str = "AgentState";
impl AddressableContent for AgentStateSnapshot {
fn content(&self) -> Content {
self.to_owned().into()
Expand Down
2 changes: 1 addition & 1 deletion core/src/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ConsistencyModel {
None
})
}
Action::Hold(EntryWithHeader { entry, header: _ }) => {
Action::Hold(EntryWithHeader { entry, .. }) => {
Some(ConsistencySignal::new_terminal(Hold(entry.address())))
}
Action::UpdateEntry((old, new)) => Some(ConsistencySignal::new_terminal(
Expand Down
4 changes: 2 additions & 2 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct P2pNetworkWrapper(Arc<Mutex<Option<P2pNetwork>>>);

impl P2pNetworkWrapper {
pub fn lock(&self) -> P2pNetworkMutexGuardWrapper<'_> {
return P2pNetworkMutexGuardWrapper(self.0.lock().expect("network accessible"));
P2pNetworkMutexGuardWrapper(self.0.lock().expect("network accessible"))
}
}

Expand Down Expand Up @@ -393,7 +393,7 @@ pub async fn get_dna_and_agent(context: &Arc<Context>) -> HcResult<(Address, Str
pub fn test_memory_network_config(network_name: Option<&str>) -> P2pConfig {
network_name
.map(|name| P2pConfig::new_with_memory_backend(name))
.unwrap_or_else(|| P2pConfig::new_with_unique_memory_backend())
.unwrap_or_else(P2pConfig::new_with_unique_memory_backend)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/dht/dht_reducers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub(crate) fn reduce_update_entry(
) -> Option<DhtStore> {
let (old_address, new_address) = unwrap_to!(action_wrapper.action() => Action::UpdateEntry);
let mut new_store = (*old_store).clone();
let res = reduce_update_entry_inner(&mut new_store, old_address, new_address);
let res = reduce_update_entry_inner(&new_store, old_address, new_address);
new_store.actions_mut().insert(action_wrapper.clone(), res);
Some(new_store)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/dht/dht_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl From<&StateWrapper> for DhtStoreSnapshot {
}
}

pub static DHT_STORE_SNAPSHOT_ADDRESS: &'static str = "DhtStore";
pub static DHT_STORE_SNAPSHOT_ADDRESS: &str = "DhtStore";
impl AddressableContent for DhtStoreSnapshot {
fn content(&self) -> Content {
self.to_owned().into()
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/actions/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn query(
let (key, payload) = match method {
QueryMethod::Entry(address) => {
let key = GetEntryKey {
address: address,
address,
id: snowflake::ProcessUniqueId::new().to_string(),
};
(QueryKey::Entry(key), QueryPayload::Entry)
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/handler/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn get_all_public_chain_entries(context: Arc<Context>) -> Vec<Address> {
fn get_all_chain_header_entries(context: Arc<Context>) -> Vec<Entry> {
let chain = context.state().unwrap().agent().iter_chain();
chain
.map(|chain_header| Entry::ChainHeader(chain_header))
.map(Entry::ChainHeader)
.collect()
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/network/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fn get_content_aspect(
log_error!(context, "{}", err_message);
HolochainError::ErrorGeneric(err_message)
})?;
if headers.len() > 0 {
if !headers.is_empty() {
// TODO: this is just taking the first header..
// We should actually transform all headers into EntryAspect::Headers and just the first one
// into an EntryAspect content (What about ordering? Using the headers timestamp?)
Expand Down Expand Up @@ -418,7 +418,7 @@ fn get_meta_aspects(
})
.partition(Result::is_ok);

if errors.len() > 0 {
if !errors.is_empty() {
Err(errors[0].to_owned().err().unwrap())
} else {
Ok(aspects.into_iter().map(Result::unwrap).collect())
Expand Down
12 changes: 4 additions & 8 deletions core/src/network/handler/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc<Context>) {
ProcessUniqueId::new().to_string()
))
.spawn(move || {
match context
.block_on(hold_entry_workflow(&entry_with_header, context.clone()))
if let Err(err) = context.block_on(hold_entry_workflow(&entry_with_header, context.clone()))
{
Err(error) => log_error!(context, "net/dht: {}", error),
_ => (),
log_error!(context, "net/dht: {}", err);
}
})
.expect("Could not spawn thread for storing EntryAspect::Content");
Expand All @@ -55,11 +53,9 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc<Context>) {
ProcessUniqueId::new().to_string()
))
.spawn(move || {
match context
.block_on(hold_link_workflow(&entry_with_header, context.clone()))
if let Err(error) = context.block_on(hold_link_workflow(&entry_with_header, context.clone()))
{
Err(error) => log_error!(context, "net/dht: {}", error),
_ => (),
log_error!(context, "net/dht: {}", error);
}
})
.expect("Could not spawn thread for storing EntryAspect::LinkAdd");
Expand Down
2 changes: 1 addition & 1 deletion core/src/network/reducers/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ mod tests {
let link_type = String::from("test-link");
let key = GetLinksKey {
base_address: entry.address(),
link_type: link_type,
link_type,
tag: "link-tag".to_string(),
id: snowflake::ProcessUniqueId::new().to_string(),
};
Expand Down
4 changes: 2 additions & 2 deletions core/src/nucleus/actions/build_validation_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mod tests {
assert!(maybe_validation_package.is_ok());

let expected = ValidationPackage {
chain_header: chain_header,
chain_header,
source_chain_entries: None,
source_chain_headers: None,
custom: None,
Expand Down Expand Up @@ -372,7 +372,7 @@ mod tests {
let headers = all_chain_headers_before_header(&context, &chain_header);

let expected = ValidationPackage {
chain_header: chain_header,
chain_header,
source_chain_entries: Some(public_chain_entries_from_headers(&context, &headers)),
source_chain_headers: Some(headers),
custom: None,
Expand Down
9 changes: 3 additions & 6 deletions core/src/nucleus/actions/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ use std::{pin::Pin, sync::Arc, time::*};
/// this consists of any public tokens that were granted for use by the container to
/// map any public calls by zome, and an optional payload for the app developer to use as
/// desired
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize,Default)]
pub struct Initialization {
public_token: Option<Address>,
payload: Option<String>,
}

impl Initialization {
pub fn new() -> Initialization {
Initialization {
public_token: None,
payload: None,
}
Initialization::default()
}
pub fn public_token(&self) -> Option<Address> {
self.public_token.clone()
Expand Down Expand Up @@ -122,7 +119,7 @@ pub async fn initialize_chain(
cap_functions.insert(zome_name, cap.functions.clone());
}
}
let public_token = if cap_functions.len() > 0 {
let public_token = if !cap_functions.is_empty() {
let maybe_public_cap_grant_entry = CapTokenGrant::create(
ReservedCapabilityId::Public.as_str(),
CapabilityType::Public,
Expand Down
5 changes: 1 addition & 4 deletions core/src/nucleus/actions/run_validation_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ pub async fn run_validation_callback(
Some(call.clone().parameters.to_bytes()),
WasmCallData::new_callback_call(cloned_context.clone(), call),
) {
Ok(call_result) => match call_result.is_null() {
true => Ok(()),
false => Err(ValidationError::Fail(call_result.to_string())),
},
Ok(call_result) => if call_result.is_null() { Ok(()) } else {Err(ValidationError::Fail(call_result.to_string()))},
// TODO: have "not matching schema" be its own error
Err(HolochainError::RibosomeFailed(error_string)) => {
if error_string == "Argument deserialization failed" {
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ZomeFnCall {
// @see https://github.com/holochain/holochain-rust/issues/198
id: snowflake::ProcessUniqueId::new(),
zome_name: zome.to_string(),
cap: cap,
cap,
fn_name: function.to_string(),
parameters: parameters.into(),
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/nucleus/ribosome/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ pub mod tests {
let (instance, context) =
test_instance_and_context(dna, netname).expect("Could not initialize test instance");
TestSetup {
context: context,
instance: instance,
context,
instance,
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/ribosome/api/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod tests {
id: "some_id".to_string(),
cap_type: CapabilityType::Assigned,
assignees: Some(vec![Address::from("fake address")]),
functions: functions,
functions,
};

JsonString::from(grant_args).to_bytes()
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/ribosome/api/init_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn invoke_init_globals(runtime: &mut Runtime, _args: &RuntimeArgs) -> ZomeAp
{
found_entries.push(chain_header.entry_address().to_owned());
}
if found_entries.len() > 0 {
if !found_entries.is_empty() {
globals.agent_latest_hash = found_entries[0].clone();
globals.agent_initial_hash = found_entries.pop().unwrap();
globals.agent_address = globals.agent_latest_hash.clone();
Expand Down
4 changes: 2 additions & 2 deletions core/src/nucleus/ribosome/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl WasmPageManager {
.expect("in module generated by rustc export named 'memory' should be a memory; qed")
.clone();

return WasmPageManager {
WasmPageManager {
stack: WasmStack::default(),
wasm_memory,
};
}
}

/// Allocate on stack without writing in it
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/ribosome/run_dna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ pub fn run_dna(parameters: Option<Vec<u8>>, data: WasmCallData) -> ZomeFnResult
// zome_call.fn_name, return_log_msg,
// );
let _ = return_log_msg;
return return_result;
return_result
}
2 changes: 1 addition & 1 deletion core/src/nucleus/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl From<NucleusStateSnapshot> for NucleusState {
}
}

pub static NUCLEUS_SNAPSHOT_ADDRESS: &'static str = "NucleusState";
pub static NUCLEUS_SNAPSHOT_ADDRESS: &str = "NucleusState";
impl AddressableContent for NucleusStateSnapshot {
fn address(&self) -> Address {
NUCLEUS_SNAPSHOT_ADDRESS.into()
Expand Down
10 changes: 5 additions & 5 deletions core/src/workflows/get_entry_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ pub async fn get_entry_result_workflow<'a>(
// Entry found
if let Some(entry_with_meta_and_headers) = maybe_entry_with_meta_and_headers {
// Erase history if request is for latest
if args.options.status_request == StatusRequestKind::Latest {
if entry_with_meta_and_headers.entry_with_meta.crud_status == CrudStatus::Deleted {
entry_result.clear();
break;
}
if args.options.status_request == StatusRequestKind::Latest && entry_with_meta_and_headers.entry_with_meta.crud_status == CrudStatus::Deleted
{
entry_result.clear();
break;

}

// Add entry
Expand Down
8 changes: 3 additions & 5 deletions core_types/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ impl AddressableContent for AgentId {
}
}

pub static GOOD_ID: &'static str =
"HcScIkRaAaaaaaaaaaAaaaAAAAaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";
pub static BAD_ID: &'static str = "HcScIkRaAaaaaaaaaaAaaaBBBBaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";
pub static TOO_BAD_ID: &'static str =
"HcScIkRaAaaaaaaaaaBBBBBBBBaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";
pub static GOOD_ID: &str = "HcScIkRaAaaaaaaaaaAaaaAAAAaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";
pub static BAD_ID: &str = "HcScIkRaAaaaaaaaaaAaaaBBBBaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";
pub static TOO_BAD_ID: &str = "HcScIkRaAaaaaaaaaaBBBBBBBBaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa";

pub fn test_agent_id() -> AgentId {
AgentId::new("bob", GOOD_ID.to_string())
Expand Down
2 changes: 1 addition & 1 deletion core_types/src/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl AddressableContent for Entry {

fn try_from_content(content: &Content) -> JsonResult<Entry> {
Entry::try_from(content.to_owned())
.or_else(|_| ChainHeader::try_from(content).map(|header| Entry::ChainHeader(header)))
.or_else(|_| ChainHeader::try_from(content).map(Entry::ChainHeader))
}
}

Expand Down
1 change: 0 additions & 1 deletion core_types/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ macro_rules! mutex_impl {
HcLockErrorKind::HcLockTimeout,
));
}

pub fn $try_lock_fn(&self) -> Option<$Guard<T>> {
(*self).inner.$try_lock_fn().map(|g| $Guard::new(g))
}
Expand Down
6 changes: 2 additions & 4 deletions hdk-rust/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ struct PartialZome {
}

#[allow(improper_ctypes)]
#[derive(Default)]
pub struct ZomeDefinition {
pub entry_types: Vec<ValidatingEntryType>,
pub agent_entry_validator: Option<AgentValidator>,
}

impl ZomeDefinition {
pub fn new() -> ZomeDefinition {
ZomeDefinition {
entry_types: Vec::new(),
agent_entry_validator: None,
}
ZomeDefinition::default()
}

#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions wasm_utils/src/memory/ribosome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub fn load_ribosome_encoded_string(
match RibosomeEncodedValue::from(encoded_value) {
RibosomeEncodedValue::Success => Err(HolochainError::Ribosome(
RibosomeErrorCode::ZeroSizedAllocation,
))?,
RibosomeEncodedValue::Failure(err_code) => Err(HolochainError::Ribosome(err_code))?,
)),
RibosomeEncodedValue::Failure(err_code) => Err(HolochainError::Ribosome(err_code)),
RibosomeEncodedValue::Allocation(ribosome_allocation) => {
Ok(WasmAllocation::try_from(ribosome_allocation)?.read_to_string())
}
Expand Down

0 comments on commit 4d1633b

Please sign in to comment.