Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 17 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ as_ptr_cast_mut = "deny"
as_underscore = "allow"
big_endian_bytes = "allow"
cognitive_complexity = "allow"
collapsible_else_if = "allow"
create_dir = "allow"
decimal_literal_representation = "allow"
doc_markdown = "allow"
doc_paragraphs_missing_punctuation = "allow"
else_if_without_else = "allow"
exhaustive_enums = "allow"
Expand All @@ -199,6 +202,7 @@ integer_division = "allow"
integer_division_remainder_used = "allow"
little_endian_bytes = "allow"
match_same_arms = "allow"
min_ident_chars = "allow"
missing_docs_in_private_items = "allow"
missing_panics_doc = "allow"
missing_trait_methods = "allow"
Expand Down Expand Up @@ -232,11 +236,7 @@ wildcard_enum_match_arm = "allow"

# TODO: Maybe fix these (need to make a decision):
cast_precision_loss = "allow"
collapsible_else_if = "allow"
create_dir = "allow"
decimal_bitwise_operands = "allow"
default_trait_access = "allow"
empty_drop = "allow"
error_impl_error = "allow"
exit = "allow"
field_scoped_visibility_modifiers = "allow"
Expand All @@ -245,79 +245,52 @@ float_cmp = "allow"
from_iter_instead_of_collect = "allow"
get_unwrap = "allow"
iter_over_hash_type = "allow"
impl_trait_in_params = "allow"
infinite_loop = "allow"
large_futures = "allow"
large_stack_arrays = "allow"
large_types_passed_by_value = "allow"
let_underscore_must_use = "allow"
mem_forget = "allow"
missing_asserts_for_indexing = "allow"
missing_errors_doc = "allow"
modulo_arithmetic = "allow"
must_use_candidate = "allow"
option_option = "allow"
panic = "allow"
panic_in_result_fn = "allow"
partial_pub_fields = "allow"
pub_underscore_fields = "allow"
rc_buffer = "allow"
should_panic_without_expect = "allow"
similar_names = "allow"
single_char_lifetime_names = "allow"
stable_sort_primitive = "allow"
string_slice = "allow"
struct_excessive_bools = "allow"
struct_field_names = "allow"
tests_outside_test_module = "allow"
unimplemented = "allow"
unnecessary_box_returns = "allow"
unnested_or_patterns = "allow"
unused_self = "allow"
unsafe_derive_deserialize = "allow"
unseparated_literal_suffix = "allow"
# TODO: `.unwrap()` hould only be allowed in tests and benchmarks
# TODO: `.unwrap()` should only be allowed in tests and benchmarks, but it requires a separate file, see
# https://github.com/rust-lang/rust-clippy/issues/17201
unwrap_used = "allow"
use_debug = "allow"

# TODO: Fix everything below:
allow_attributes_without_reason = "allow"
# TODO: It'd be nice to have this, but there is way too much code that uses it correctly that would be very unergonomic
# to change. Waiting for a brave soul to do something about it eventually.
arithmetic_side_effects = "allow"
as_conversions = "allow"
assertions_on_result_states = "allow"
borrow_as_ptr = "allow"
# TODO: It'd be nice to have this, but there is way too much code that uses it correctly that would be very unergonomic
# to change. Waiting for a brave soul to do something about it eventually.
cast_possible_truncation = "allow"
cast_ptr_alignment = "allow"
doc_link_with_quotes = "allow"
doc_markdown = "allow"
ignore_without_reason = "allow"
ignored_unit_patterns = "allow"
indexing_slicing = "allow"
# TODO: Currently used for very context-specific workarounds for `generic_const_exprs` that would be awkward to rewrite
items_after_statements = "allow"
many_single_char_names = "allow"
min_ident_chars = "allow"
missing_assert_message = "allow"
missing_inline_in_public_items = "allow"
multiple_inherent_impl = "allow"
needless_borrows_for_generic_args = "allow"
ref_patterns = "allow"
return_self_not_must_use = "allow"
same_length_and_capacity = "allow"
same_name_method = "allow"
# TODO: It will require either suppresing when macros are used or report upstream that macro-generated code should not
# be linted with this
semicolon_if_nothing_returned = "allow"
single_char_lifetime_names = "allow"
single_call_fn = "allow"
trivially_copy_pass_by_ref = "allow"
unchecked_time_subtraction = "allow"
unused_async = "allow"
verbose_file_reads = "allow"
wildcard_imports = "allow"

# TODO: False-positives that need to be fixed in Clippy
# TODO: Fix once false-positives are resolved: https://github.com/rust-lang/rust-clippy/issues/16745
Expand All @@ -328,5 +301,15 @@ elidable_lifetime_names = "allow"
non_zero_suggestions = "allow"
# TODO: False-positives: https://github.com/rust-lang/rust-clippy/issues/17043
redundant_type_annotations = "allow"
# TODO: Waiting on https://github.com/paritytech/parity-scale-codec/pull/820 or https://github.com/rust-lang/rust-clippy/issues/17198
ref_patterns = "allow"
# TODO: Waiting on https://github.com/paritytech/parity-scale-codec/pull/820 or https://github.com/rust-lang/rust-clippy/issues/17199
semicolon_if_nothing_returned = "allow"
# TODO: False-positives: https://github.com/rust-lang/rust-clippy/issues/11024
tests_outside_test_module = "allow"
# TODO: False-positives: https://github.com/rust-lang/rust-clippy/issues/17202
unnecessary_box_returns = "allow"
# TODO: Re-enable once false-positive is resolved: https://github.com/rust-lang/rust-clippy/issues/17039
unnecessary_safety_comment = "allow"
# TODO: https://github.com/rust-lang/rust-clippy/issues/5368#issuecomment-4665479346
verbose_file_reads = "allow"
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// TODO: Remove once fixed
#![expect(
clippy::borrow_as_ptr,
reason = "https://github.com/NobodyXu/derive_destructure2/pull/6"
)]

use crate::metadata::ContractMetadataKind;
use ab_io_type::metadata::{IoTypeDetails, IoTypeMetadataKind};
use core::mem::ManuallyDrop;
Expand Down
15 changes: 14 additions & 1 deletion crates/contracts/core/ab-contracts-macros-impl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn process_trait_definition(mut item_trait: ItemTrait) -> Result<TokenStream, Er
#ext_trait

/// FFI code generated by procedural macro
#[expect(clippy::wildcard_imports, reason = "Macro-generated")]
pub mod ffi {
use super::*;

Expand Down Expand Up @@ -261,10 +262,10 @@ fn process_trait_impl(mut item_impl: ItemImpl, trait_name: &Ident) -> Result<Tok
}

/// FFI code generated by procedural macro
#[expect(clippy::wildcard_imports, reason = "Macro-generated")]
pub mod #ffi_mod_ident {
use super::*;


#( #guest_ffis )*
}
})
Expand Down Expand Up @@ -330,6 +331,12 @@ fn process_struct_impl(mut item_impl: ItemImpl) -> Result<TokenStream, Error> {
));
}

// Needed for arguments
item_impl.attrs.extend([
parse_quote! { #[expect(clippy::allow_attributes, reason = "Attribute below")] },
parse_quote! { #[allow(clippy::trivially_copy_pass_by_ref, reason = "API requirement")] },
]);

let mut guest_ffis = Vec::with_capacity(item_impl.items.len());
let mut trait_ext_components = Vec::with_capacity(item_impl.items.len());
let mut contract_details = ContractDetails::default();
Expand Down Expand Up @@ -518,6 +525,7 @@ fn process_struct_impl(mut item_impl: ItemImpl) -> Result<TokenStream, Error> {
#ext_trait

/// FFI code generated by procedural macro
#[expect(clippy::wildcard_imports, reason = "Macro-generated")]
pub mod ffi {
use super::*;

Expand Down Expand Up @@ -684,13 +692,18 @@ fn generate_extension_trait(
.map(|components| &components.r#impl);

quote! {
#[expect(clippy::wildcard_imports, reason = "Macro-generated")]
use ffi::*;

#[doc = #trait_doc]
#[automatically_derived]
#[expect(clippy::allow_attributes, reason = "Attribute below")]
#[allow(clippy::trivially_copy_pass_by_ref, reason = "API requirement")]
pub trait #trait_name {
#( #definitions )*
}

#[automatically_derived]
impl #trait_name for ::ab_contracts_macros::__private::Env<'_> {
#( #impls )*
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::contract::common::{derive_ident_metadata, extract_ident_from_type};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::token::Paren;
use syn::{
Attribute, Error, GenericArgument, Meta, Pat, PatType, PathArguments, ReturnType, Signature,
Token, Type, TypeTuple,
Expand Down Expand Up @@ -73,8 +75,8 @@ enum MethodReturnType {
impl MethodReturnType {
fn unit_type() -> Type {
Type::Tuple(TypeTuple {
paren_token: Default::default(),
elems: Default::default(),
paren_token: Paren::default(),
elems: Punctuated::default(),
})
}

Expand Down Expand Up @@ -983,10 +985,16 @@ impl MethodDetails {
#[doc = #args_struct_doc]
#[derive(::core::fmt::Debug)]
#[repr(C)]
#[expect(
clippy::partial_pub_fields,
reason = "Not needed to be constructed publicly, but does need to always store \
the lifetime"
)]
#[allow(clippy::pub_underscore_fields, reason = "Comes from user-provided arguments")]
pub struct InternalArgs<'internal_args>
{
#( #internal_args_pointers )*
_phantom: ::core::marker::PhantomData<&'internal_args ()>,
lifetime: ::core::marker::PhantomData<&'internal_args ()>,
}
}
};
Expand Down Expand Up @@ -1082,6 +1090,7 @@ impl MethodDetails {

quote! {
#[doc(hidden)]
#[expect(clippy::wildcard_imports, reason = "Macro-generated")]
pub mod fn_pointer {
use super::*;

Expand Down Expand Up @@ -1260,9 +1269,11 @@ impl MethodDetails {
#[doc = #args_struct_doc]
#[derive(::core::fmt::Debug)]
#[repr(C)]
#[allow(clippy::pub_underscore_fields, reason = "Comes from user-provided arguments")]
pub struct #args_struct_name<'external_args> {
#( #external_args_fields )*
lifetime: ::core::marker::PhantomData<&'external_args ()>,
/// Lifetime of the struct
pub _lifetime: ::core::marker::PhantomData<&'external_args ()>,
}

#[automatically_derived]
Expand All @@ -1287,7 +1298,7 @@ impl MethodDetails {
) -> Self {
Self {
#( #method_args_fields )*
lifetime: ::core::marker::PhantomData,
_lifetime: ::core::marker::PhantomData,
}
}
}
Expand Down Expand Up @@ -1576,6 +1587,7 @@ impl MethodDetails {
quote_spanned! {fn_sig.span() =>
#[allow(dead_code, reason = "Macro-generated")]
#[allow(clippy::used_underscore_binding, reason = "Macro-generated")]
#[allow(clippy::semicolon_if_nothing_returned, reason = "Macro-generated")]
fn #ext_method_name(
#env_self,
#method_context_arg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ab_contracts_standards::tx_handler::TxHandler;
use ab_core_primitives::address::Address;
use ab_core_primitives::block::BlockRoot;
use ab_core_primitives::shard::ShardIndex;
use ab_core_primitives::transaction::{Transaction, TransactionHeader, TransactionSlot};
use ab_core_primitives::transaction::{Gas, Transaction, TransactionHeader, TransactionSlot};
use ab_example_contract_wallet::{ExampleWallet, ExampleWalletExt};
use ab_executor_native::NativeExecutor;
use ab_io_type::bool::Bool;
Expand Down Expand Up @@ -88,7 +88,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let header = TransactionHeader {
version: 0,
block_root: BlockRoot::default(),
gas_limit: Default::default(),
gas_limit: Gas::default(),
contract: wallet_address,
};
let payload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ab_contracts_standards::tx_handler::TxHandler;
use ab_core_primitives::address::Address;
use ab_core_primitives::block::BlockRoot;
use ab_core_primitives::shard::ShardIndex;
use ab_core_primitives::transaction::{Transaction, TransactionHeader, TransactionSlot};
use ab_core_primitives::transaction::{Gas, Transaction, TransactionHeader, TransactionSlot};
use ab_example_contract_wallet::{ExampleWallet, ExampleWalletExt};
use ab_executor_native::NativeExecutor;
use ab_io_type::bool::Bool;
Expand Down Expand Up @@ -90,7 +90,7 @@ fn flip() {
let header = TransactionHeader {
version: 0,
block_root: BlockRoot::default(),
gas_limit: Default::default(),
gas_limit: Gas::default(),
contract: wallet_address,
};
let payload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ impl<'a> TransactionPayloadDecoder<'a> {
map_context,
}
}
}

impl<'a> TransactionPayloadDecoder<'a> {
/// Decode the next method (if any) in the payload
#[cfg_attr(feature = "no-panic", no_panic::no_panic)]
pub fn decode_next_method(
Expand Down
7 changes: 5 additions & 2 deletions crates/execution/ab-riscv-interpreter/src/rv32/c/zca/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::rv32::test_utils::{TEST_BASE_ADDR, execute, initialize_state};
use crate::{ExecutableInstruction, ExecutionError, ProgramCounter, RegisterFile, VirtualMemory};
use crate::{
ExecutableInstruction, ExecutionError, ProgramCounter, RegisterFile, Rs1Rs2OperandValues,
VirtualMemory,
};
use ab_riscv_primitives::prelude::*;

// C.ADDI4SPN
Expand Down Expand Up @@ -112,7 +115,7 @@ fn test_cjal_negative_offset() {
};
let (rd, rd_value) = instruction
.execute(
Default::default(),
Rs1Rs2OperandValues::default(),
&mut state.regs,
&mut state.ext_state,
&mut state.memory,
Expand Down
4 changes: 4 additions & 0 deletions crates/execution/ab-riscv-interpreter/src/rv32/m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ where
Self::Rem { rd, rs1: _, rs2: _ } => {
let dividend = rs1_value.cast_signed();
let divisor = rs2_value.cast_signed();
#[expect(
clippy::modulo_arithmetic,
reason = "This is what the code is supposed to do"
)]
let value = if divisor == 0 {
dividend
} else if dividend == i32::MIN && divisor == -1 {
Expand Down
8 changes: 8 additions & 0 deletions crates/execution/ab-riscv-interpreter/src/rv64/m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ where
Self::Rem { rd, rs1: _, rs2: _ } => {
let dividend = rs1_value.cast_signed();
let divisor = rs2_value.cast_signed();
#[expect(
clippy::modulo_arithmetic,
reason = "This is what the code is supposed to do"
)]
let value = if divisor == 0 {
dividend
} else if dividend == i64::MIN && divisor == -1 {
Expand Down Expand Up @@ -140,6 +144,10 @@ where
Self::Remw { rd, rs1: _, rs2: _ } => {
let dividend = rs1_value as i32;
let divisor = rs2_value as i32;
#[expect(
clippy::modulo_arithmetic,
reason = "This is what the code is supposed to do"
)]
let value = if divisor == 0 {
i64::from(dividend).cast_unsigned()
} else if dividend == i32::MIN && divisor == -1 {
Expand Down
Loading
Loading