Skip to content

Commit fdae394

Browse files
authored
Merge pull request #3946 from stacks-network/chore/clarity-fix-clippy
Chore/clarity fix clippy
2 parents d9a4f8d + 3af3051 commit fdae394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1709
-2054
lines changed

clarity/src/libclarity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ const GIT_COMMIT: Option<&'static str> = option_env!("GIT_COMMIT");
101101
const GIT_TREE_CLEAN: Option<&'static str> = option_env!("GIT_TREE_CLEAN");
102102

103103
#[cfg(debug_assertions)]
104-
const BUILD_TYPE: &'static str = "debug";
104+
const BUILD_TYPE: &str = "debug";
105105
#[cfg(not(debug_assertions))]
106-
const BUILD_TYPE: &'static str = "release";
106+
const BUILD_TYPE: &str = "release";
107107

108108
pub fn version_string(pkg_name: &str, pkg_version: &str) -> String {
109109
let git_branch = GIT_BRANCH.unwrap_or("");

clarity/src/vm/analysis/analysis_db.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ impl<'a> AnalysisDatabase<'a> {
4848
F: FnOnce(&mut Self) -> Result<T, E>,
4949
{
5050
self.begin();
51-
let result = f(self).or_else(|e| {
51+
let result = f(self).map_err(|e| {
5252
self.roll_back();
53-
Err(e)
53+
e
5454
})?;
5555
self.commit();
5656
Ok(result)
@@ -111,9 +111,9 @@ impl<'a> AnalysisDatabase<'a> {
111111
// the analysis will propagate that as a CheckError anyways.
112112
.ok()?
113113
.map(|x| ContractAnalysis::deserialize(&x))
114-
.and_then(|mut x| {
114+
.map(|mut x| {
115115
x.canonicalize_types(epoch);
116-
Some(x)
116+
x
117117
})
118118
}
119119

@@ -161,7 +161,7 @@ impl<'a> AnalysisDatabase<'a> {
161161
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
162162
Ok(contract
163163
.get_public_function_type(function_name)
164-
.and_then(|x| Some(x.canonicalize(epoch))))
164+
.map(|x| x.canonicalize(epoch)))
165165
}
166166

167167
pub fn get_read_only_function_type(
@@ -179,7 +179,7 @@ impl<'a> AnalysisDatabase<'a> {
179179
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
180180
Ok(contract
181181
.get_read_only_function_type(function_name)
182-
.and_then(|x| Some(x.canonicalize(epoch))))
182+
.map(|x| x.canonicalize(epoch)))
183183
}
184184

185185
pub fn get_defined_trait(
@@ -195,16 +195,12 @@ impl<'a> AnalysisDatabase<'a> {
195195
let contract = self
196196
.load_contract_non_canonical(contract_identifier)
197197
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
198-
Ok(contract
199-
.get_defined_trait(trait_name)
200-
.and_then(|trait_map| {
201-
Some(
202-
trait_map
203-
.into_iter()
204-
.map(|(name, sig)| (name.clone(), sig.canonicalize(epoch)))
205-
.collect(),
206-
)
207-
}))
198+
Ok(contract.get_defined_trait(trait_name).map(|trait_map| {
199+
trait_map
200+
.iter()
201+
.map(|(name, sig)| (name.clone(), sig.canonicalize(epoch)))
202+
.collect()
203+
}))
208204
}
209205

210206
pub fn get_implemented_traits(

clarity/src/vm/analysis/arithmetic_checker/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a> ArithmeticOnlyChecker<'a> {
8282
clarity_version: &contract_analysis.clarity_version,
8383
};
8484
for exp in contract_analysis.expressions.iter() {
85-
checker.check_top_levels(&exp)?;
85+
checker.check_top_levels(exp)?;
8686
}
8787

8888
Ok(())
@@ -147,7 +147,7 @@ impl<'a> ArithmeticOnlyChecker<'a> {
147147
fn check_variables_allowed(&self, var_name: &ClarityName) -> Result<(), Error> {
148148
use crate::vm::variables::NativeVariables::*;
149149
if let Some(native_var) =
150-
NativeVariables::lookup_by_name_at_version(var_name, &self.clarity_version)
150+
NativeVariables::lookup_by_name_at_version(var_name, self.clarity_version)
151151
{
152152
match native_var {
153153
ContractCaller | TxSender | TotalLiquidMicroSTX | BlockHeight | BurnBlockHeight
@@ -182,26 +182,22 @@ impl<'a> ArithmeticOnlyChecker<'a> {
182182
| MintToken | TransferAsset | TransferToken | ContractCall | StxTransfer
183183
| StxTransferMemo | StxBurn | AtBlock | GetStxBalance | GetTokenSupply | BurnToken
184184
| FromConsensusBuff | ToConsensusBuff | BurnAsset | StxGetAccount => {
185-
return Err(Error::FunctionNotPermitted(function));
185+
Err(Error::FunctionNotPermitted(function))
186186
}
187187
Append | Concat | AsMaxLen | ContractOf | PrincipalOf | ListCons | Print
188188
| AsContract | ElementAt | ElementAtAlias | IndexOf | IndexOfAlias | Map | Filter
189-
| Fold | Slice | ReplaceAt => {
190-
return Err(Error::FunctionNotPermitted(function));
191-
}
189+
| Fold | Slice | ReplaceAt => Err(Error::FunctionNotPermitted(function)),
192190
BuffToIntLe | BuffToUIntLe | BuffToIntBe | BuffToUIntBe => {
193-
return Err(Error::FunctionNotPermitted(function));
191+
Err(Error::FunctionNotPermitted(function))
194192
}
195193
IsStandard | PrincipalDestruct | PrincipalConstruct => {
196-
return Err(Error::FunctionNotPermitted(function));
194+
Err(Error::FunctionNotPermitted(function))
197195
}
198196
IntToAscii | IntToUtf8 | StringToInt | StringToUInt => {
199-
return Err(Error::FunctionNotPermitted(function));
197+
Err(Error::FunctionNotPermitted(function))
200198
}
201199
Sha512 | Sha512Trunc256 | Secp256k1Recover | Secp256k1Verify | Hash160 | Sha256
202-
| Keccak256 => {
203-
return Err(Error::FunctionNotPermitted(function));
204-
}
200+
| Keccak256 => Err(Error::FunctionNotPermitted(function)),
205201
Add | Subtract | Divide | Multiply | CmpGeq | CmpLeq | CmpLess | CmpGreater
206202
| Modulo | Power | Sqrti | Log2 | BitwiseXor | And | Or | Not | Equals | If
207203
| ConsSome | ConsOkay | ConsError | DefaultTo | UnwrapRet | UnwrapErrRet | IsOkay

clarity/src/vm/analysis/contract_interface_builder/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ use std::collections::{BTreeMap, BTreeSet};
2727
use crate::vm::ClarityVersion;
2828

2929
pub fn build_contract_interface(contract_analysis: &ContractAnalysis) -> ContractInterface {
30-
let mut contract_interface = ContractInterface::new(
31-
contract_analysis.epoch.clone(),
32-
contract_analysis.clarity_version.clone(),
33-
);
30+
let mut contract_interface =
31+
ContractInterface::new(contract_analysis.epoch, contract_analysis.clarity_version);
3432

3533
let ContractAnalysis {
3634
private_function_types,
@@ -165,7 +163,7 @@ pub struct ContractInterfaceNonFungibleTokens {
165163

166164
impl ContractInterfaceAtomType {
167165
pub fn from_tuple_type(tuple_type: &TupleTypeSignature) -> ContractInterfaceAtomType {
168-
ContractInterfaceAtomType::tuple(Self::vec_from_tuple_type(&tuple_type))
166+
ContractInterfaceAtomType::tuple(Self::vec_from_tuple_type(tuple_type))
169167
}
170168

171169
pub fn vec_from_tuple_type(
@@ -214,13 +212,13 @@ impl ContractInterfaceAtomType {
214212
}
215213
}
216214
OptionalType(sig) => {
217-
ContractInterfaceAtomType::optional(Box::new(Self::from_type_signature(&sig)))
215+
ContractInterfaceAtomType::optional(Box::new(Self::from_type_signature(sig)))
218216
}
219217
TypeSignature::ResponseType(boxed_sig) => {
220218
let (ok_sig, err_sig) = boxed_sig.as_ref();
221219
ContractInterfaceAtomType::response {
222-
ok: Box::new(Self::from_type_signature(&ok_sig)),
223-
error: Box::new(Self::from_type_signature(&err_sig)),
220+
ok: Box::new(Self::from_type_signature(ok_sig)),
221+
error: Box::new(Self::from_type_signature(err_sig)),
224222
}
225223
}
226224
}
@@ -237,7 +235,7 @@ pub struct ContractInterfaceFunctionArg {
237235
impl ContractInterfaceFunctionArg {
238236
pub fn from_function_args(fnArgs: &[FunctionArg]) -> Vec<ContractInterfaceFunctionArg> {
239237
let mut args: Vec<ContractInterfaceFunctionArg> = Vec::new();
240-
for ref fnArg in fnArgs.iter() {
238+
for fnArg in fnArgs.iter() {
241239
args.push(ContractInterfaceFunctionArg {
242240
name: fnArg.name.to_string(),
243241
type_f: ContractInterfaceAtomType::from_type_signature(&fnArg.signature),
@@ -273,7 +271,7 @@ impl ContractInterfaceFunction {
273271
outputs: ContractInterfaceFunctionOutput {
274272
type_f: match function_type {
275273
FunctionType::Fixed(FixedFunction { returns, .. }) => {
276-
ContractInterfaceAtomType::from_type_signature(&returns)
274+
ContractInterfaceAtomType::from_type_signature(returns)
277275
}
278276
_ => panic!(
279277
"Contract functions should only have fixed function return types!"
@@ -282,7 +280,7 @@ impl ContractInterfaceFunction {
282280
},
283281
args: match function_type {
284282
FunctionType::Fixed(FixedFunction { args, .. }) => {
285-
ContractInterfaceFunctionArg::from_function_args(&args)
283+
ContractInterfaceFunctionArg::from_function_args(args)
286284
}
287285
_ => panic!("Contract functions should only have fixed function arguments!"),
288286
},

0 commit comments

Comments
 (0)