Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacks-common to clippy CI and fix errors #5598

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p libstackerdb -p stacks-signer -p pox-locking --no-deps --tests --all-features -- -D warnings
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings
8 changes: 4 additions & 4 deletions clarity/src/vm/analysis/analysis_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl<'a> AnalysisDatabase<'a> {
self.begin();
let result = f(self).or_else(|e| {
self.roll_back()
.map_err(|e| CheckErrors::Expects(format!("{e:?}")).into())?;
.map_err(|e| CheckErrors::Expects(format!("{e:?}")))?;
Err(e)
})?;
self.commit()
.map_err(|e| CheckErrors::Expects(format!("{e:?}")).into())?;
.map_err(|e| CheckErrors::Expects(format!("{e:?}")))?;
Ok(result)
}

Expand Down Expand Up @@ -130,9 +130,9 @@ impl<'a> AnalysisDatabase<'a> {
.map_err(|_| CheckErrors::Expects("Bad data deserialized from DB".into()))
})
.transpose()?
.and_then(|mut x| {
.map(|mut x| {
x.canonicalize_types(epoch);
Some(x)
x
}))
}

Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/arithmetic_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl std::fmt::Display for Error {
}
}

impl<'a> ArithmeticOnlyChecker<'a> {
impl ArithmeticOnlyChecker<'_> {
pub fn check_contract_cost_eligible(contract_analysis: &mut ContractAnalysis) {
let is_eligible = ArithmeticOnlyChecker::run(contract_analysis).is_ok();
contract_analysis.is_cost_contract_eligible = is_eligible;
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/analysis/contract_interface_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl ContractInterfaceFunction {
outputs: ContractInterfaceFunctionOutput {
type_f: match function_type {
FunctionType::Fixed(FixedFunction { returns, .. }) => {
ContractInterfaceAtomType::from_type_signature(&returns)
ContractInterfaceAtomType::from_type_signature(returns)
}
_ => return Err(CheckErrors::Expects(
"Contract functions should only have fixed function return types!"
Expand All @@ -287,7 +287,7 @@ impl ContractInterfaceFunction {
},
args: match function_type {
FunctionType::Fixed(FixedFunction { args, .. }) => {
ContractInterfaceFunctionArg::from_function_args(&args)
ContractInterfaceFunctionArg::from_function_args(args)
}
_ => {
return Err(CheckErrors::Expects(
Expand Down
10 changes: 5 additions & 5 deletions clarity/src/vm/analysis/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ impl CheckErrors {
/// Does this check error indicate that the transaction should be
/// rejected?
pub fn rejectable(&self) -> bool {
match &self {
CheckErrors::SupertypeTooLarge | CheckErrors::Expects(_) => true,
_ => false,
}
matches!(
self,
CheckErrors::SupertypeTooLarge | CheckErrors::Expects(_)
)
}
}

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

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

if expected_types.len() > 2 {
Expand Down
6 changes: 3 additions & 3 deletions clarity/src/vm/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
pub mod analysis_db;
pub mod arithmetic_checker;
pub mod contract_interface_builder;
#[allow(clippy::result_large_err)]
pub mod errors;
pub mod read_only_checker;
pub mod trait_checker;
Expand Down Expand Up @@ -52,7 +51,7 @@ pub fn mem_type_check(
epoch: StacksEpochId,
) -> CheckResult<(Option<TypeSignature>, ContractAnalysis)> {
let contract_identifier = QualifiedContractIdentifier::transient();
let mut contract = build_ast_with_rules(
let contract = build_ast_with_rules(
&contract_identifier,
snippet,
&mut (),
Expand All @@ -68,7 +67,7 @@ pub fn mem_type_check(
let cost_tracker = LimitedCostTracker::new_free();
match run_analysis(
&QualifiedContractIdentifier::transient(),
&mut contract,
&contract,
&mut analysis_db,
false,
cost_tracker,
Expand Down Expand Up @@ -120,6 +119,7 @@ pub fn type_check(
.map_err(|(e, _cost_tracker)| e)
}

#[allow(clippy::too_many_arguments)]
pub fn run_analysis(
contract_identifier: &QualifiedContractIdentifier,
expressions: &[SymbolicExpression],
Expand Down
19 changes: 9 additions & 10 deletions clarity/src/vm/analysis/read_only_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct ReadOnlyChecker<'a, 'b> {
clarity_version: ClarityVersion,
}

impl<'a, 'b> AnalysisPass for ReadOnlyChecker<'a, 'b> {
impl AnalysisPass for ReadOnlyChecker<'_, '_> {
fn run_pass(
epoch: &StacksEpochId,
contract_analysis: &mut ContractAnalysis,
Expand Down Expand Up @@ -250,13 +250,12 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
Ok(result)
}

/// Checks the native function application of the function named by the
/// string `function` to `args` to determine whether it is read-only
/// compliant.
/// Checks the native function application of the function named by the string `function`
/// to `args` to determine whether it is read-only compliant.
///
/// - Returns `None` if there is no native function named `function`.
/// - If there is such a native function, returns `true` iff this function application is
/// read-only.
/// - If there is such a native function, returns `true` iff this function
/// application is read-only.
///
/// # Errors
/// - Contract parsing errors
Expand Down Expand Up @@ -414,15 +413,15 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}
}

/// Checks the native and user-defined function applications implied by `expressions`. The
/// first expression is used as the function name, and the tail expressions are used as the
/// arguments.
/// Checks the native and user-defined function applications implied by `expressions`.
///
/// The first expression is used as the function name, and the tail expressions are used as the arguments.
///
/// Returns `true` iff the function application is read-only.
///
/// # Errors
/// - `CheckErrors::NonFunctionApplication` if there is no first expression, or if the first
/// expression is not a `ClarityName`.
/// expression is not a `ClarityName`.
/// - `CheckErrors::UnknownFunction` if the first expression does not name a known function.
fn check_expression_application_is_read_only(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/type_checker/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl TypeMap {
}
}

impl<'a> TypingContext<'a> {
impl TypingContext<'_> {
pub fn new(epoch: StacksEpochId, clarity_version: ClarityVersion) -> TypingContext<'static> {
TypingContext {
epoch,
Expand Down
9 changes: 3 additions & 6 deletions clarity/src/vm/analysis/type_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl FunctionType {
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => self.check_args_2_1(accounting, args, clarity_version),
StacksEpochId::Epoch10 => {
return Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
}
}
}
Expand All @@ -81,17 +81,14 @@ impl FunctionType {
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
}
StacksEpochId::Epoch10 => {
return Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
}
}
}
}

fn is_reserved_word_v3(word: &str) -> bool {
match word {
"block-height" => true,
_ => false,
}
word == "block-height"
}

/// Is this a reserved word that should trigger an analysis error for the given
Expand Down
75 changes: 35 additions & 40 deletions clarity/src/vm/analysis/type_checker/v2_05/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ impl FunctionType {
Ok(TypeSignature::BoolType)
}
FunctionType::Binary(_, _, _) => {
return Err(CheckErrors::Expects(
"Binary type should not be reached in 2.05".into(),
)
.into())
Err(CheckErrors::Expects("Binary type should not be reached in 2.05".into()).into())
}
}
}
Expand Down Expand Up @@ -286,8 +283,8 @@ impl FunctionType {
)?;
}
(expected_type, value) => {
if !expected_type.admits(&StacksEpochId::Epoch2_05, &value)? {
let actual_type = TypeSignature::type_of(&value)?;
if !expected_type.admits(&StacksEpochId::Epoch2_05, value)? {
let actual_type = TypeSignature::type_of(value)?;
return Err(
CheckErrors::TypeError(expected_type.clone(), actual_type).into()
);
Expand Down Expand Up @@ -438,41 +435,39 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
context: &TypingContext,
expected_type: &TypeSignature,
) -> TypeResult {
match (&expr.expr, expected_type) {
(
LiteralValue(Value::Principal(PrincipalData::Contract(ref contract_identifier))),
TypeSignature::TraitReferenceType(trait_identifier),
) => {
let contract_to_check = self
.db
.load_contract(&contract_identifier, &StacksEpochId::Epoch2_05)?
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;

let contract_defining_trait = self
.db
.load_contract(
&trait_identifier.contract_identifier,
&StacksEpochId::Epoch2_05,
)?
.ok_or(CheckErrors::NoSuchContract(
trait_identifier.contract_identifier.to_string(),
))?;

let trait_definition = contract_defining_trait
.get_defined_trait(&trait_identifier.name)
.ok_or(CheckErrors::NoSuchTrait(
trait_identifier.contract_identifier.to_string(),
trait_identifier.name.to_string(),
))?;

contract_to_check.check_trait_compliance(
if let (
LiteralValue(Value::Principal(PrincipalData::Contract(ref contract_identifier))),
TypeSignature::TraitReferenceType(trait_identifier),
) = (&expr.expr, expected_type)
{
let contract_to_check = self
.db
.load_contract(contract_identifier, &StacksEpochId::Epoch2_05)?
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;

let contract_defining_trait = self
.db
.load_contract(
&trait_identifier.contract_identifier,
&StacksEpochId::Epoch2_05,
trait_identifier,
trait_definition,
)?;
return Ok(expected_type.clone());
}
(_, _) => {}
)?
.ok_or(CheckErrors::NoSuchContract(
trait_identifier.contract_identifier.to_string(),
))?;

let trait_definition = contract_defining_trait
.get_defined_trait(&trait_identifier.name)
.ok_or(CheckErrors::NoSuchTrait(
trait_identifier.contract_identifier.to_string(),
trait_identifier.name.to_string(),
))?;

contract_to_check.check_trait_compliance(
&StacksEpochId::Epoch2_05,
trait_identifier,
trait_definition,
)?;
return Ok(expected_type.clone());
}

let actual_type = self.type_check(expr, context)?;
Expand Down
3 changes: 1 addition & 2 deletions clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,7 @@ impl TypedNativeFunction {
| ReplaceAt | GetStacksBlockInfo | GetTenureInfo => {
return Err(CheckErrors::Expects(
"Clarity 2+ keywords should not show up in 2.05".into(),
)
.into())
))
}
};

Expand Down
Loading
Loading