Skip to content

Commit

Permalink
Address clippy complaints in src/vm/
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Sep 22, 2023
1 parent a3bf299 commit 264831e
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 209 deletions.
35 changes: 16 additions & 19 deletions clarity/src/vm/callables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ use super::costs::CostOverflowingMath;
use super::types::signatures::CallableSubtype;
use super::ClarityVersion;

type SpecialFunctionType =
dyn Fn(&[SymbolicExpression], &mut Environment, &LocalContext) -> Result<Value>;

pub enum CallableType {
UserFunction(DefinedFunction),
NativeFunction(&'static str, NativeHandle, ClarityCostFunction),
Expand All @@ -52,10 +55,7 @@ pub enum CallableType {
ClarityCostFunction,
&'static dyn Fn(&[Value]) -> Result<u64>,
),
SpecialFunction(
&'static str,
&'static dyn Fn(&[SymbolicExpression], &mut Environment, &LocalContext) -> Result<Value>,
),
SpecialFunction(&'static str, &'static SpecialFunctionType),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -237,7 +237,11 @@ impl DefinedFunction {
)
.into());
}
if let Some(_) = context.variables.insert(name.clone(), value.clone()) {
if context
.variables
.insert(name.clone(), value.clone())
.is_some()
{
return Err(CheckErrors::NameAlreadyUsed(name.to_string()).into());
}
}
Expand Down Expand Up @@ -279,7 +283,7 @@ impl DefinedFunction {
}
}

if let Some(_) = context.variables.insert(name.clone(), cast_value) {
if context.variables.insert(name.clone(), cast_value).is_some() {
return Err(CheckErrors::NameAlreadyUsed(name.to_string()).into());
}
}
Expand Down Expand Up @@ -316,7 +320,7 @@ impl DefinedFunction {
self.name.to_string(),
))?;

let args = self.arg_types.iter().map(|a| a.clone()).collect();
let args = self.arg_types.to_vec();
if !expected_sig.check_args_trait_compliance(epoch, args)? {
return Err(
CheckErrors::BadTraitImplementation(trait_name, self.name.to_string()).into(),
Expand Down Expand Up @@ -386,16 +390,12 @@ impl CallableType {
impl FunctionIdentifier {
fn new_native_function(name: &str) -> FunctionIdentifier {
let identifier = format!("_native_:{}", name);
FunctionIdentifier {
identifier: identifier,
}
FunctionIdentifier { identifier }
}

fn new_user_function(name: &str, context: &str) -> FunctionIdentifier {
let identifier = format!("{}:{}", context, name);
FunctionIdentifier {
identifier: identifier,
}
FunctionIdentifier { identifier }
}
}

Expand Down Expand Up @@ -620,12 +620,9 @@ mod test {
let cast_list = clarity2_implicit_cast(&list_opt_ty, &list_opt_contract).unwrap();
let items = cast_list.expect_list();
for item in items {
match item.expect_optional() {
Some(cast_opt) => {
let cast_trait = cast_opt.expect_callable();
assert_eq!(&cast_trait.trait_identifier.unwrap(), &trait_identifier);
}
None => (),
if let Some(cast_opt) = item.expect_optional() {
let cast_trait = cast_opt.expect_callable();
assert_eq!(&cast_trait.trait_identifier.unwrap(), &trait_identifier);
}
}

Expand Down
3 changes: 2 additions & 1 deletion clarity/src/vm/clarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub trait ClarityConnection {
self.with_clarity_db_readonly_owned(|mut db| (to_do(&mut db), db))
}

#[allow(clippy::too_many_arguments)]
fn with_readonly_clarity_env<F, R>(
&mut self,
mainnet: bool,
Expand Down Expand Up @@ -262,7 +263,7 @@ pub trait TransactionConnection: ClarityConnection {
},
|_, _| false,
)
.and_then(|(value, assets, events, _)| Ok((value, assets, events)))
.map(|(value, assets, events, _)| (value, assets, events))
}

/// Execute a contract call in the current block.
Expand Down
Loading

0 comments on commit 264831e

Please sign in to comment.