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

chore: reduce clippy warnings #5254

Merged
merged 4 commits into from
Nov 27, 2024
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
1 change: 1 addition & 0 deletions crates/iroha_config_base/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Error {
}
}

#[expect(clippy::too_long_first_doc_paragraph)]
/// The reader, which provides an API to accumulate config sources,
/// read parameters from them, override with environment variables, fallback to default values,
/// and finally, construct an exhaustive error report with as many errors, accumulated along the
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod isi {
)?;
let asset = state_transaction
.world
.asset_or_insert(asset_id.clone(), self.object.value)
.asset_or_insert(&asset_id, self.object.value)
.expect("Account exists");

match asset.value {
Expand Down
8 changes: 4 additions & 4 deletions crates/iroha_core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod isi {

let asset = state_transaction
.world
.asset_or_insert(asset_id.clone(), Metadata::default())?;
.asset_or_insert(&asset_id, Metadata::default())?;

{
let AssetValue::Store(store) = &mut asset.value else {
Expand Down Expand Up @@ -153,7 +153,7 @@ pub mod isi {
AssetId::new(asset_id.definition.clone(), self.destination.clone());
let destination_store_asset = state_transaction
.world
.asset_or_insert(destination_id.clone(), value)?;
.asset_or_insert(&destination_id, value)?;

destination_store_asset.clone()
};
Expand Down Expand Up @@ -185,7 +185,7 @@ pub mod isi {
assert_can_mint(&asset_definition, state_transaction)?;
let asset = state_transaction
.world
.asset_or_insert(asset_id.clone(), Numeric::ZERO)?;
.asset_or_insert(&asset_id, Numeric::ZERO)?;
let AssetValue::Numeric(quantity) = &mut asset.value else {
return Err(Error::Conversion("Expected numeric asset type".to_owned()));
};
Expand Down Expand Up @@ -312,7 +312,7 @@ pub mod isi {

let destination_asset = state_transaction
.world
.asset_or_insert(destination_id.clone(), Numeric::ZERO)?;
.asset_or_insert(&destination_id, Numeric::ZERO)?;
{
let AssetValue::Numeric(quantity) = &mut destination_asset.value else {
return Err(Error::Conversion("Expected numeric asset type".to_owned()));
Expand Down
1 change: 1 addition & 0 deletions crates/iroha_core/src/smartcontracts/isi/triggers/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ impl<'block, 'set> SetTransaction<'block, 'set> {
}
}

#[expect(clippy::too_long_first_doc_paragraph)]
/// Same as [`Executable`](iroha_data_model::transaction::Executable), but instead of
/// [`Wasm`](iroha_data_model::transaction::Executable::Wasm) contains hash of the WASM blob
/// Which can be used to obtain compiled by `wasmtime` module
Expand Down
6 changes: 3 additions & 3 deletions crates/iroha_core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,14 @@ impl WorldTransaction<'_, '_> {
#[allow(clippy::missing_panics_doc)]
pub fn asset_or_insert(
&mut self,
asset_id: AssetId,
asset_id: &AssetId,
default_asset_value: impl Into<AssetValue>,
) -> Result<&mut Asset, Error> {
self.domain(&asset_id.definition.domain)?;
self.asset_definition(&asset_id.definition)?;
self.account(&asset_id.account)?;

if self.assets.get(&asset_id).is_none() {
if self.assets.get(asset_id).is_none() {
let asset = Asset::new(asset_id.clone(), default_asset_value.into());

Self::emit_events_impl(
Expand All @@ -876,7 +876,7 @@ impl WorldTransaction<'_, '_> {
}
Ok(self
.assets
.get_mut(&asset_id)
.get_mut(asset_id)
.expect("Just inserted, cannot fail."))
}

Expand Down
1 change: 1 addition & 0 deletions crates/iroha_crypto/src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ macro_rules! from_uint(
let zeros = n.leading_zeros();
let end = core::mem::size_of::<$ty>() * 8 - zeros as usize;

#[allow(clippy::cast_possible_truncation)]
let mut payload = (0..end)
.step_by(7)
.map(|offset| (((n >> offset) as u8) | 0b1000_0000))
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_data_model/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl FromStr for Peer {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.rsplit_once("@") {
match s.rsplit_once('@') {
None => Err(ParseError {
reason: "Peer should have format `public_key@address`",
}),
Expand Down
6 changes: 5 additions & 1 deletion crates/iroha_data_model/src/query/builder/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ where
T: HasTypedBatchIter,
{
fn len(&self) -> usize {
self.current_batch_iter.len() + self.remaining_items as usize
self.remaining_items
.try_into()
.ok()
.and_then(|r: usize| r.checked_add(self.current_batch_iter.len()))
.expect("should be within the range of usize")
}
}
2 changes: 2 additions & 0 deletions crates/iroha_data_model/src/query/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub trait QueryExecutor {
/// # Errors
///
/// Returns an error if the query execution fails.
#[expect(clippy::type_complexity)]
fn start_query(
&self,
query: QueryWithParams,
Expand All @@ -57,6 +58,7 @@ pub trait QueryExecutor {
/// # Errors
///
/// Returns an error if the query execution fails.
#[expect(clippy::type_complexity)]
fn continue_query(
cursor: Self::Cursor,
) -> Result<(QueryOutputBatchBoxTuple, u64, Option<Self::Cursor>), Self::Error>;
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn serde_where(arguments: TokenStream, item: TokenStream) -> TokenStream {
return emitter.finish_token_stream_with(derive_input.into_token_stream());
};

let result = serde_where::impl_serde_where(&mut emitter, arguments, derive_input);
let result = serde_where::impl_serde_where(&mut emitter, &arguments, derive_input);

emitter.finish_token_stream_with(result)
}
6 changes: 3 additions & 3 deletions crates/iroha_derive/src/serde_where.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl syn::parse::Parse for SerdeWhereArguments {

pub fn impl_serde_where(
_emitter: &mut Emitter,
arguments: SerdeWhereArguments,
arguments: &SerdeWhereArguments,
mut input: syn::DeriveInput,
) -> TokenStream {
fn make_bound<F>(arguments: &SerdeWhereArguments, f: F) -> String
Expand All @@ -37,12 +37,12 @@ pub fn impl_serde_where(
bound.to_string()
}

let serialize_bound = make_bound(&arguments, |ty| {
let serialize_bound = make_bound(arguments, |ty| {
parse_quote! {
#ty: serde::Serialize
}
});
let deserialize_bound = make_bound(&arguments, |ty| {
let deserialize_bound = make_bound(arguments, |ty| {
parse_quote! {
#ty: serde::Deserialize<'de>
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_numeric/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl NumericSpec {

/// Get the scale
#[inline]
pub const fn scale(&self) -> Option<u32> {
pub const fn scale(self) -> Option<u32> {
self.scale
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/iroha_schema/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Serialize for WithContext<'_, '_, ArrayMeta> {
}
}
impl PartialEq for WithContext<'_, '_, ArrayMeta> {
#[expect(clippy::suspicious_operation_groupings)]
fn eq(&self, other: &Self) -> bool {
self.type_name(self.data.ty) == other.type_name(other.data.ty)
&& self.data.len == other.data.len
Expand All @@ -67,6 +68,7 @@ impl Serialize for WithContext<'_, '_, Declaration> {
}
}
impl PartialEq for WithContext<'_, '_, Declaration> {
#[expect(clippy::suspicious_operation_groupings)]
fn eq(&self, other: &Self) -> bool {
self.data.name == other.data.name
&& self.type_name(self.data.ty) == other.type_name(other.data.ty)
Expand Down Expand Up @@ -208,6 +210,7 @@ impl Serialize for WithContext<'_, '_, FixedMeta> {
}
}
impl PartialEq for WithContext<'_, '_, FixedMeta> {
#[expect(clippy::suspicious_operation_groupings)]
fn eq(&self, other: &Self) -> bool {
self.data.decimal_places == other.data.decimal_places
&& self.type_name(self.data.base) == other.type_name(other.data.base)
Expand All @@ -226,6 +229,7 @@ impl Serialize for WithContext<'_, '_, BitmapMeta> {
}
}
impl PartialEq for WithContext<'_, '_, BitmapMeta> {
#[expect(clippy::suspicious_operation_groupings)]
fn eq(&self, other: &Self) -> bool {
self.type_name(self.data.repr) == other.type_name(other.data.repr)
&& self.data.masks == other.data.masks
Expand Down
10 changes: 5 additions & 5 deletions crates/iroha_telemetry_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream {
return emitter.finish_token_stream();
};

let result = impl_metrics(&mut emitter, metric_specs, &func);
let result = impl_metrics(&mut emitter, &metric_specs, &func);

emitter.finish_token_stream_with(result)
}

fn impl_metrics(
emitter: &mut Emitter,
#[cfg_attr(not(feature = "metric-instrumentation"), expect(unused))] specs: MetricSpecs,
#[cfg_attr(not(feature = "metric-instrumentation"), expect(unused))] specs: &MetricSpecs,
func: &syn::ItemFn,
) -> TokenStream {
let syn::ItemFn {
Expand Down Expand Up @@ -247,7 +247,7 @@ fn impl_metrics(

// #[cfg(feature = "metric-instrumentation")]
// {
// let (totals, successes, times) = write_metrics(metric_arg_ident, specs);
// let (totals, successes, times) = write_metrics(metric_arg_ident, &specs);
// quote!(
// #(#attrs)* #vis #sig {
// let closure = || #block;
Expand Down Expand Up @@ -275,8 +275,8 @@ fn impl_metrics(
// FIXME: metrics were removed https://github.com/hyperledger-iroha/iroha/issues/5134
#[cfg(feature = "metric-instrumentation")]
fn write_metrics(
metric_arg_ident: proc_macro2::Ident,
specs: MetricSpecs,
metric_arg_ident: &proc_macro2::Ident,
specs: &MetricSpecs,
) -> (TokenStream, TokenStream, TokenStream) {
let inc_metric = |spec: &MetricSpec, kind: &str| {
quote!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn visit_custom_instruction(executor: &mut Executor, isi: &CustomInstruction) {
deny!(executor, "Failed to parse custom instruction");
};
match execute_custom_instruction(isi, executor.host()) {
Ok(()) => return,
Ok(()) => (),
Err(err) => {
deny!(executor, err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn visit_custom_instruction(executor: &mut Executor, isi: &CustomInstruction) {
deny!(executor, "Failed to parse custom instruction");
};
match execute_custom_instruction(isi, executor.host()) {
Ok(()) => return,
Ok(()) => (),
Err(err) => {
deny!(executor, err);
}
Expand Down
2 changes: 0 additions & 2 deletions wasm/samples/executor_with_custom_permission/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ static ALLOC: GlobalDlmalloc = GlobalDlmalloc;

// FIXME: Don't derive manually (https://github.com/hyperledger-iroha/iroha/issues/3834)
visit_grant_role_permission,
visit_grant_role_permission,
visit_revoke_role_permission,
visit_revoke_role_permission
))]
struct Executor {
host: Iroha,
Expand Down
Loading