Skip to content

Commit

Permalink
chore: more clippy lints (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketpr01 authored Jul 16, 2024
1 parent bd7c629 commit a8ee4e2
Show file tree
Hide file tree
Showing 55 changed files with 504 additions and 408 deletions.
75 changes: 75 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,78 @@ no_unknown_fields = [
"starknet-core/no_unknown_fields",
"starknet-providers/no_unknown_fields",
]

[workspace.lints]
rust.missing_debug_implementations = "warn"
rust.missing_docs = "allow"
rust.unreachable_pub = "allow"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rustdoc.all = "warn"

[workspace.lints.clippy]
# These are some of clippy's nursery (i.e., experimental) lints that we like.
# By default, nursery lints are allowed. Some of the lints below have made good
# suggestions which we fixed. The others didn't have any findings, so we can
# assume they don't have that many false positives. Let's enable them to
# prevent future problems.
branches_sharing_code = "warn"
clear_with_drain = "warn"
derive_partial_eq_without_eq = "warn"
empty_line_after_outer_attr = "warn"
equatable_if_let = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_with_drain = "warn"
large_stack_frames = "warn"
manual_clamp = "warn"
mutex_integer = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
tuple_array_conversions = "warn"
uninhabited_references = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
useless_let_if_seq = "warn"
use_self = "warn"
missing_const_for_fn = "warn"
empty_line_after_doc_comments = "warn"
iter_on_single_items = "warn"
match_same_arms = "warn"
doc_markdown = "warn"
unnecessary_struct_initialization = "warn"
string_lit_as_bytes = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
type_repetition_in_bounds = "allow"
manual_string_new = "warn"
naive_bytecount = "warn"
needless_bitwise_bool = "warn"
zero_sized_map_values = "warn"
single_char_pattern = "warn"
needless_continue = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
# quite mature enough for use in our codebase and some we don't really want.
# Explicitly listing should make it easier to fix in the future.
as_ptr_cast_mut = "allow"
cognitive_complexity = "allow"
collection_is_never_read = "allow"
debug_assert_with_mut_call = "allow"
fallible_impl_from = "allow"
future_not_send = "allow"
needless_collect = "allow"
non_send_fields_in_send_ty = "allow"
redundant_pub_crate = "allow"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"
3 changes: 3 additions & 0 deletions starknet-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
tokio = { version = "1.27.0", features = ["full"] }
url = "2.3.1"

[lints]
workspace = true
32 changes: 16 additions & 16 deletions starknet-accounts/src/account/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const QUERY_VERSION_THREE: Felt = Felt::from_raw([
]);

impl<'a, A> DeclarationV2<'a, A> {
pub fn new(
pub const fn new(
contract_class: Arc<FlattenedSierraClass>,
compiled_class_hash: Felt,
account: &'a A,
Expand Down Expand Up @@ -88,8 +88,8 @@ impl<'a, A> DeclarationV2<'a, A> {
}
}

/// Calling this function after manually specifying `nonce` and `max_fee` turns [DeclarationV2]
/// into [PreparedDeclarationV2]. Returns `Err` if either field is `None`.
/// Calling this function after manually specifying `nonce` and `max_fee` turns [`DeclarationV2`]
/// into [`PreparedDeclarationV2`]. Returns `Err` if either field is `None`.
pub fn prepared(self) -> Result<PreparedDeclarationV2<'a, A>, NotPreparedError> {
let nonce = self.nonce.ok_or(NotPreparedError)?;
let max_fee = self.max_fee.ok_or(NotPreparedError)?;
Expand Down Expand Up @@ -275,7 +275,7 @@ where
}

impl<'a, A> DeclarationV3<'a, A> {
pub fn new(
pub const fn new(
contract_class: Arc<FlattenedSierraClass>,
compiled_class_hash: Felt,
account: &'a A,
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<'a, A> DeclarationV3<'a, A> {
}

/// Calling this function after manually specifying `nonce`, `gas` and `gas_price` turns
/// [DeclarationV3] into [PreparedDeclarationV3]. Returns `Err` if any field is `None`.
/// [`DeclarationV3`] into [`PreparedDeclarationV3`]. Returns `Err` if any field is `None`.
pub fn prepared(self) -> Result<PreparedDeclarationV3<'a, A>, NotPreparedError> {
let nonce = self.nonce.ok_or(NotPreparedError)?;
let gas = self.gas.ok_or(NotPreparedError)?;
Expand Down Expand Up @@ -570,7 +570,7 @@ where
}

impl<'a, A> LegacyDeclaration<'a, A> {
pub fn new(contract_class: Arc<LegacyContractClass>, account: &'a A) -> Self {
pub const fn new(contract_class: Arc<LegacyContractClass>, account: &'a A) -> Self {
Self {
account,
contract_class,
Expand Down Expand Up @@ -602,7 +602,7 @@ impl<'a, A> LegacyDeclaration<'a, A> {
}

/// Calling this function after manually specifying `nonce` and `max_fee` turns
/// [LegacyDeclaration] into [PreparedLegacyDeclaration]. Returns `Err` if either field is
/// [`LegacyDeclaration`] into [`PreparedLegacyDeclaration`]. Returns `Err` if either field is
/// `None`.
pub fn prepared(self) -> Result<PreparedLegacyDeclaration<'a, A>, NotPreparedError> {
let nonce = self.nonce.ok_or(NotPreparedError)?;
Expand Down Expand Up @@ -809,15 +809,15 @@ impl RawDeclarationV2 {
&self.contract_class
}

pub fn compiled_class_hash(&self) -> Felt {
pub const fn compiled_class_hash(&self) -> Felt {
self.compiled_class_hash
}

pub fn nonce(&self) -> Felt {
pub const fn nonce(&self) -> Felt {
self.nonce
}

pub fn max_fee(&self) -> Felt {
pub const fn max_fee(&self) -> Felt {
self.max_fee
}
}
Expand Down Expand Up @@ -880,19 +880,19 @@ impl RawDeclarationV3 {
&self.contract_class
}

pub fn compiled_class_hash(&self) -> Felt {
pub const fn compiled_class_hash(&self) -> Felt {
self.compiled_class_hash
}

pub fn nonce(&self) -> Felt {
pub const fn nonce(&self) -> Felt {
self.nonce
}

pub fn gas(&self) -> u64 {
pub const fn gas(&self) -> u64 {
self.gas
}

pub fn gas_price(&self) -> u128 {
pub const fn gas_price(&self) -> u128 {
self.gas_price
}
}
Expand Down Expand Up @@ -924,11 +924,11 @@ impl RawLegacyDeclaration {
&self.contract_class
}

pub fn nonce(&self) -> Felt {
pub const fn nonce(&self) -> Felt {
self.nonce
}

pub fn max_fee(&self) -> Felt {
pub const fn max_fee(&self) -> Felt {
self.max_fee
}
}
Expand Down
20 changes: 10 additions & 10 deletions starknet-accounts/src/account/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const QUERY_VERSION_THREE: Felt = Felt::from_raw([
]);

impl<'a, A> ExecutionV1<'a, A> {
pub fn new(calls: Vec<Call>, account: &'a A) -> Self {
pub const fn new(calls: Vec<Call>, account: &'a A) -> Self {
Self {
account,
calls,
Expand Down Expand Up @@ -72,8 +72,8 @@ impl<'a, A> ExecutionV1<'a, A> {
}
}

/// Calling this function after manually specifying `nonce` and `max_fee` turns [ExecutionV1] into
/// [PreparedExecutionV1]. Returns `Err` if either field is `None`.
/// Calling this function after manually specifying `nonce` and `max_fee` turns [`ExecutionV1`] into
/// [`PreparedExecutionV1`]. Returns `Err` if either field is `None`.
pub fn prepared(self) -> Result<PreparedExecutionV1<'a, A>, NotPreparedError> {
let nonce = self.nonce.ok_or(NotPreparedError)?;
let max_fee = self.max_fee.ok_or(NotPreparedError)?;
Expand All @@ -90,7 +90,7 @@ impl<'a, A> ExecutionV1<'a, A> {
}

impl<'a, A> ExecutionV3<'a, A> {
pub fn new(calls: Vec<Call>, account: &'a A) -> Self {
pub const fn new(calls: Vec<Call>, account: &'a A) -> Self {
Self {
account,
calls,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<'a, A> ExecutionV3<'a, A> {
}

/// Calling this function after manually specifying `nonce`, `gas` and `gas_price` turns
/// [ExecutionV3] into [PreparedExecutionV3]. Returns `Err` if any field is `None`.
/// [`ExecutionV3`] into [`PreparedExecutionV3`]. Returns `Err` if any field is `None`.
pub fn prepared(self) -> Result<PreparedExecutionV3<'a, A>, NotPreparedError> {
let nonce = self.nonce.ok_or(NotPreparedError)?;
let gas = self.gas.ok_or(NotPreparedError)?;
Expand Down Expand Up @@ -583,11 +583,11 @@ impl RawExecutionV1 {
&self.calls
}

pub fn nonce(&self) -> Felt {
pub const fn nonce(&self) -> Felt {
self.nonce
}

pub fn max_fee(&self) -> Felt {
pub const fn max_fee(&self) -> Felt {
self.max_fee
}
}
Expand Down Expand Up @@ -667,15 +667,15 @@ impl RawExecutionV3 {
&self.calls
}

pub fn nonce(&self) -> Felt {
pub const fn nonce(&self) -> Felt {
self.nonce
}

pub fn gas(&self) -> u64 {
pub const fn gas(&self) -> u64 {
self.gas
}

pub fn gas_price(&self) -> u128 {
pub const fn gas_price(&self) -> u128 {
self.gas_price
}
}
Expand Down
Loading

0 comments on commit a8ee4e2

Please sign in to comment.