Skip to content

Commit 932969e

Browse files
committed
Fix clarity clippy warnings and add clarity to clippy ci workflow
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 906c012 commit 932969e

Some content is hidden

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

53 files changed

+635
-697
lines changed

.github/workflows/clippy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
uses: actions-rs/clippy-check@v1
3838
with:
3939
token: ${{ secrets.GITHUB_TOKEN }}
40-
args: -p libstackerdb -p stacks-signer -p pox-locking --no-deps --tests --all-features -- -D warnings
40+
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity --no-deps --tests --all-features -- -D warnings

clarity/src/vm/analysis/analysis_db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ impl<'a> AnalysisDatabase<'a> {
5050
self.begin();
5151
let result = f(self).or_else(|e| {
5252
self.roll_back()
53-
.map_err(|e| CheckErrors::Expects(format!("{e:?}")).into())?;
53+
.map_err(|e| CheckErrors::Expects(format!("{e:?}")))?;
5454
Err(e)
5555
})?;
5656
self.commit()
57-
.map_err(|e| CheckErrors::Expects(format!("{e:?}")).into())?;
57+
.map_err(|e| CheckErrors::Expects(format!("{e:?}")))?;
5858
Ok(result)
5959
}
6060

@@ -130,9 +130,9 @@ impl<'a> AnalysisDatabase<'a> {
130130
.map_err(|_| CheckErrors::Expects("Bad data deserialized from DB".into()))
131131
})
132132
.transpose()?
133-
.and_then(|mut x| {
133+
.map(|mut x| {
134134
x.canonicalize_types(epoch);
135-
Some(x)
135+
x
136136
}))
137137
}
138138

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl std::fmt::Display for Error {
6868
}
6969
}
7070

71-
impl<'a> ArithmeticOnlyChecker<'a> {
71+
impl ArithmeticOnlyChecker<'_> {
7272
pub fn check_contract_cost_eligible(contract_analysis: &mut ContractAnalysis) {
7373
let is_eligible = ArithmeticOnlyChecker::run(contract_analysis).is_ok();
7474
contract_analysis.is_cost_contract_eligible = is_eligible;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl ContractInterfaceFunction {
276276
outputs: ContractInterfaceFunctionOutput {
277277
type_f: match function_type {
278278
FunctionType::Fixed(FixedFunction { returns, .. }) => {
279-
ContractInterfaceAtomType::from_type_signature(&returns)
279+
ContractInterfaceAtomType::from_type_signature(returns)
280280
}
281281
_ => return Err(CheckErrors::Expects(
282282
"Contract functions should only have fixed function return types!"
@@ -287,7 +287,7 @@ impl ContractInterfaceFunction {
287287
},
288288
args: match function_type {
289289
FunctionType::Fixed(FixedFunction { args, .. }) => {
290-
ContractInterfaceFunctionArg::from_function_args(&args)
290+
ContractInterfaceFunctionArg::from_function_args(args)
291291
}
292292
_ => {
293293
return Err(CheckErrors::Expects(

clarity/src/vm/analysis/errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ impl CheckErrors {
207207
/// Does this check error indicate that the transaction should be
208208
/// rejected?
209209
pub fn rejectable(&self) -> bool {
210-
match &self {
211-
CheckErrors::SupertypeTooLarge | CheckErrors::Expects(_) => true,
212-
_ => false,
213-
}
210+
matches!(
211+
self,
212+
CheckErrors::SupertypeTooLarge | CheckErrors::Expects(_)
213+
)
214214
}
215215
}
216216

@@ -323,7 +323,7 @@ pub fn check_arguments_at_most<T>(expected: usize, args: &[T]) -> Result<(), Che
323323
}
324324
}
325325

326-
fn formatted_expected_types(expected_types: &Vec<TypeSignature>) -> String {
326+
fn formatted_expected_types(expected_types: &[TypeSignature]) -> String {
327327
let mut expected_types_joined = format!("'{}'", expected_types[0]);
328328

329329
if expected_types.len() > 2 {

clarity/src/vm/analysis/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
pub mod analysis_db;
1818
pub mod arithmetic_checker;
1919
pub mod contract_interface_builder;
20-
#[allow(clippy::result_large_err)]
2120
pub mod errors;
2221
pub mod read_only_checker;
2322
pub mod trait_checker;
@@ -52,7 +51,7 @@ pub fn mem_type_check(
5251
epoch: StacksEpochId,
5352
) -> CheckResult<(Option<TypeSignature>, ContractAnalysis)> {
5453
let contract_identifier = QualifiedContractIdentifier::transient();
55-
let mut contract = build_ast_with_rules(
54+
let contract = build_ast_with_rules(
5655
&contract_identifier,
5756
snippet,
5857
&mut (),
@@ -68,7 +67,7 @@ pub fn mem_type_check(
6867
let cost_tracker = LimitedCostTracker::new_free();
6968
match run_analysis(
7069
&QualifiedContractIdentifier::transient(),
71-
&mut contract,
70+
&contract,
7271
&mut analysis_db,
7372
false,
7473
cost_tracker,
@@ -120,6 +119,7 @@ pub fn type_check(
120119
.map_err(|(e, _cost_tracker)| e)
121120
}
122121

122+
#[allow(clippy::too_many_arguments)]
123123
pub fn run_analysis(
124124
contract_identifier: &QualifiedContractIdentifier,
125125
expressions: &[SymbolicExpression],

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct ReadOnlyChecker<'a, 'b> {
5050
clarity_version: ClarityVersion,
5151
}
5252

53-
impl<'a, 'b> AnalysisPass for ReadOnlyChecker<'a, 'b> {
53+
impl AnalysisPass for ReadOnlyChecker<'_, '_> {
5454
fn run_pass(
5555
epoch: &StacksEpochId,
5656
contract_analysis: &mut ContractAnalysis,
@@ -250,13 +250,12 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
250250
Ok(result)
251251
}
252252

253-
/// Checks the native function application of the function named by the
254-
/// string `function` to `args` to determine whether it is read-only
255-
/// compliant.
253+
/// Checks the native function application of the function named by the string `function`
254+
/// to `args` to determine whether it is read-only compliant.
256255
///
257256
/// - Returns `None` if there is no native function named `function`.
258-
/// - If there is such a native function, returns `true` iff this function application is
259-
/// read-only.
257+
/// - If there is such a native function, returns `true` iff this function
258+
/// application is read-only.
260259
///
261260
/// # Errors
262261
/// - Contract parsing errors
@@ -414,15 +413,15 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
414413
}
415414
}
416415

417-
/// Checks the native and user-defined function applications implied by `expressions`. The
418-
/// first expression is used as the function name, and the tail expressions are used as the
419-
/// arguments.
416+
/// Checks the native and user-defined function applications implied by `expressions`.
417+
///
418+
/// The first expression is used as the function name, and the tail expressions are used as the arguments.
420419
///
421420
/// Returns `true` iff the function application is read-only.
422421
///
423422
/// # Errors
424423
/// - `CheckErrors::NonFunctionApplication` if there is no first expression, or if the first
425-
/// expression is not a `ClarityName`.
424+
/// expression is not a `ClarityName`.
426425
/// - `CheckErrors::UnknownFunction` if the first expression does not name a known function.
427426
fn check_expression_application_is_read_only(
428427
&mut self,

clarity/src/vm/analysis/type_checker/contexts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl TypeMap {
9292
}
9393
}
9494

95-
impl<'a> TypingContext<'a> {
95+
impl TypingContext<'_> {
9696
pub fn new(epoch: StacksEpochId, clarity_version: ClarityVersion) -> TypingContext<'static> {
9797
TypingContext {
9898
epoch,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl FunctionType {
5555
| StacksEpochId::Epoch30
5656
| StacksEpochId::Epoch31 => self.check_args_2_1(accounting, args, clarity_version),
5757
StacksEpochId::Epoch10 => {
58-
return Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
58+
Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
5959
}
6060
}
6161
}
@@ -81,17 +81,14 @@ impl FunctionType {
8181
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
8282
}
8383
StacksEpochId::Epoch10 => {
84-
return Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
84+
Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
8585
}
8686
}
8787
}
8888
}
8989

9090
fn is_reserved_word_v3(word: &str) -> bool {
91-
match word {
92-
"block-height" => true,
93-
_ => false,
94-
}
91+
word == "block-height"
9592
}
9693

9794
/// Is this a reserved word that should trigger an analysis error for the given

clarity/src/vm/analysis/type_checker/v2_05/mod.rs

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,7 @@ impl FunctionType {
239239
Ok(TypeSignature::BoolType)
240240
}
241241
FunctionType::Binary(_, _, _) => {
242-
return Err(CheckErrors::Expects(
243-
"Binary type should not be reached in 2.05".into(),
244-
)
245-
.into())
242+
Err(CheckErrors::Expects("Binary type should not be reached in 2.05".into()).into())
246243
}
247244
}
248245
}
@@ -286,8 +283,8 @@ impl FunctionType {
286283
)?;
287284
}
288285
(expected_type, value) => {
289-
if !expected_type.admits(&StacksEpochId::Epoch2_05, &value)? {
290-
let actual_type = TypeSignature::type_of(&value)?;
286+
if !expected_type.admits(&StacksEpochId::Epoch2_05, value)? {
287+
let actual_type = TypeSignature::type_of(value)?;
291288
return Err(
292289
CheckErrors::TypeError(expected_type.clone(), actual_type).into()
293290
);
@@ -438,41 +435,39 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
438435
context: &TypingContext,
439436
expected_type: &TypeSignature,
440437
) -> TypeResult {
441-
match (&expr.expr, expected_type) {
442-
(
443-
LiteralValue(Value::Principal(PrincipalData::Contract(ref contract_identifier))),
444-
TypeSignature::TraitReferenceType(trait_identifier),
445-
) => {
446-
let contract_to_check = self
447-
.db
448-
.load_contract(&contract_identifier, &StacksEpochId::Epoch2_05)?
449-
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
450-
451-
let contract_defining_trait = self
452-
.db
453-
.load_contract(
454-
&trait_identifier.contract_identifier,
455-
&StacksEpochId::Epoch2_05,
456-
)?
457-
.ok_or(CheckErrors::NoSuchContract(
458-
trait_identifier.contract_identifier.to_string(),
459-
))?;
460-
461-
let trait_definition = contract_defining_trait
462-
.get_defined_trait(&trait_identifier.name)
463-
.ok_or(CheckErrors::NoSuchTrait(
464-
trait_identifier.contract_identifier.to_string(),
465-
trait_identifier.name.to_string(),
466-
))?;
467-
468-
contract_to_check.check_trait_compliance(
438+
if let (
439+
LiteralValue(Value::Principal(PrincipalData::Contract(ref contract_identifier))),
440+
TypeSignature::TraitReferenceType(trait_identifier),
441+
) = (&expr.expr, expected_type)
442+
{
443+
let contract_to_check = self
444+
.db
445+
.load_contract(contract_identifier, &StacksEpochId::Epoch2_05)?
446+
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
447+
448+
let contract_defining_trait = self
449+
.db
450+
.load_contract(
451+
&trait_identifier.contract_identifier,
469452
&StacksEpochId::Epoch2_05,
470-
trait_identifier,
471-
trait_definition,
472-
)?;
473-
return Ok(expected_type.clone());
474-
}
475-
(_, _) => {}
453+
)?
454+
.ok_or(CheckErrors::NoSuchContract(
455+
trait_identifier.contract_identifier.to_string(),
456+
))?;
457+
458+
let trait_definition = contract_defining_trait
459+
.get_defined_trait(&trait_identifier.name)
460+
.ok_or(CheckErrors::NoSuchTrait(
461+
trait_identifier.contract_identifier.to_string(),
462+
trait_identifier.name.to_string(),
463+
))?;
464+
465+
contract_to_check.check_trait_compliance(
466+
&StacksEpochId::Epoch2_05,
467+
trait_identifier,
468+
trait_definition,
469+
)?;
470+
return Ok(expected_type.clone());
476471
}
477472

478473
let actual_type = self.type_check(expr, context)?;

0 commit comments

Comments
 (0)