From 03219f6cd43d32363dbd940c3daa95879961c125 Mon Sep 17 00:00:00 2001 From: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:30:23 +0900 Subject: [PATCH 1/2] chore: reduce clippy warnings Signed-off-by: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> --- crates/iroha_config_base/src/read.rs | 1 + crates/iroha_core/src/smartcontracts/isi/account.rs | 2 +- crates/iroha_core/src/smartcontracts/isi/asset.rs | 8 ++++---- .../iroha_core/src/smartcontracts/isi/triggers/set.rs | 1 + crates/iroha_core/src/state.rs | 6 +++--- crates/iroha_crypto/src/varint.rs | 1 + crates/iroha_data_model/src/peer.rs | 2 +- crates/iroha_data_model/src/query/builder.rs | 3 +++ crates/iroha_derive/src/lib.rs | 2 +- crates/iroha_derive/src/serde_where.rs | 6 +++--- crates/iroha_numeric/src/lib.rs | 2 +- crates/iroha_schema/src/serialize.rs | 4 ++++ crates/iroha_telemetry_derive/src/lib.rs | 10 +++++----- .../executor_custom_instructions_complex/src/lib.rs | 2 +- .../executor_custom_instructions_simple/src/lib.rs | 2 +- .../samples/executor_with_custom_permission/src/lib.rs | 2 -- 16 files changed, 31 insertions(+), 23 deletions(-) diff --git a/crates/iroha_config_base/src/read.rs b/crates/iroha_config_base/src/read.rs index 0812a6dfaf3..142b935df93 100644 --- a/crates/iroha_config_base/src/read.rs +++ b/crates/iroha_config_base/src/read.rs @@ -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 diff --git a/crates/iroha_core/src/smartcontracts/isi/account.rs b/crates/iroha_core/src/smartcontracts/isi/account.rs index 914b1311b12..4756bd9b505 100644 --- a/crates/iroha_core/src/smartcontracts/isi/account.rs +++ b/crates/iroha_core/src/smartcontracts/isi/account.rs @@ -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 { diff --git a/crates/iroha_core/src/smartcontracts/isi/asset.rs b/crates/iroha_core/src/smartcontracts/isi/asset.rs index 9db957022ca..cd0f0b5653f 100644 --- a/crates/iroha_core/src/smartcontracts/isi/asset.rs +++ b/crates/iroha_core/src/smartcontracts/isi/asset.rs @@ -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 { @@ -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() }; @@ -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())); }; @@ -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())); diff --git a/crates/iroha_core/src/smartcontracts/isi/triggers/set.rs b/crates/iroha_core/src/smartcontracts/isi/triggers/set.rs index 43eb9efe721..0584aa5a1a1 100644 --- a/crates/iroha_core/src/smartcontracts/isi/triggers/set.rs +++ b/crates/iroha_core/src/smartcontracts/isi/triggers/set.rs @@ -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 diff --git a/crates/iroha_core/src/state.rs b/crates/iroha_core/src/state.rs index e549c393dd6..5e146ca816c 100644 --- a/crates/iroha_core/src/state.rs +++ b/crates/iroha_core/src/state.rs @@ -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, ) -> 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( @@ -876,7 +876,7 @@ impl WorldTransaction<'_, '_> { } Ok(self .assets - .get_mut(&asset_id) + .get_mut(asset_id) .expect("Just inserted, cannot fail.")) } diff --git a/crates/iroha_crypto/src/varint.rs b/crates/iroha_crypto/src/varint.rs index 9dc990f6d14..6de218d105b 100644 --- a/crates/iroha_crypto/src/varint.rs +++ b/crates/iroha_crypto/src/varint.rs @@ -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)) diff --git a/crates/iroha_data_model/src/peer.rs b/crates/iroha_data_model/src/peer.rs index c7205bb2942..33c31a5ac46 100644 --- a/crates/iroha_data_model/src/peer.rs +++ b/crates/iroha_data_model/src/peer.rs @@ -107,7 +107,7 @@ impl FromStr for Peer { type Err = ParseError; fn from_str(s: &str) -> Result { - match s.rsplit_once("@") { + match s.rsplit_once('@') { None => Err(ParseError { reason: "Peer should have format `public_key@address`", }), diff --git a/crates/iroha_data_model/src/query/builder.rs b/crates/iroha_data_model/src/query/builder.rs index bafe5e1df1d..95b9501af48 100644 --- a/crates/iroha_data_model/src/query/builder.rs +++ b/crates/iroha_data_model/src/query/builder.rs @@ -39,6 +39,7 @@ pub trait QueryExecutor { /// # Errors /// /// Returns an error if the query execution fails. + #[expect(clippy::type_complexity)] fn start_query( &self, query: QueryWithParams, @@ -49,6 +50,7 @@ pub trait QueryExecutor { /// # Errors /// /// Returns an error if the query execution fails. + #[expect(clippy::type_complexity)] fn continue_query( cursor: Self::Cursor, ) -> Result<(QueryOutputBatchBox, u64, Option), Self::Error>; @@ -130,6 +132,7 @@ where Vec: TryFrom, as TryFrom>::Error: core::fmt::Debug, { + #[expect(clippy::cast_possible_truncation)] fn len(&self) -> usize { self.current_batch_iter.len() + self.remaining_items as usize } diff --git a/crates/iroha_derive/src/lib.rs b/crates/iroha_derive/src/lib.rs index aea054f5219..b520a83e325 100644 --- a/crates/iroha_derive/src/lib.rs +++ b/crates/iroha_derive/src/lib.rs @@ -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) } diff --git a/crates/iroha_derive/src/serde_where.rs b/crates/iroha_derive/src/serde_where.rs index f121564ab4f..3fb087cc897 100644 --- a/crates/iroha_derive/src/serde_where.rs +++ b/crates/iroha_derive/src/serde_where.rs @@ -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(arguments: &SerdeWhereArguments, f: F) -> String @@ -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> } diff --git a/crates/iroha_numeric/src/lib.rs b/crates/iroha_numeric/src/lib.rs index c7166cf7ff0..b3477553f39 100644 --- a/crates/iroha_numeric/src/lib.rs +++ b/crates/iroha_numeric/src/lib.rs @@ -327,7 +327,7 @@ impl NumericSpec { /// Get the scale #[inline] - pub const fn scale(&self) -> Option { + pub const fn scale(self) -> Option { self.scale } } diff --git a/crates/iroha_schema/src/serialize.rs b/crates/iroha_schema/src/serialize.rs index 7383ca0cd5c..fd5058e9bd8 100644 --- a/crates/iroha_schema/src/serialize.rs +++ b/crates/iroha_schema/src/serialize.rs @@ -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 @@ -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) @@ -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) @@ -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 diff --git a/crates/iroha_telemetry_derive/src/lib.rs b/crates/iroha_telemetry_derive/src/lib.rs index f376f38f7f0..1f9d101b775 100644 --- a/crates/iroha_telemetry_derive/src/lib.rs +++ b/crates/iroha_telemetry_derive/src/lib.rs @@ -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 { @@ -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; @@ -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!( diff --git a/wasm/samples/executor_custom_instructions_complex/src/lib.rs b/wasm/samples/executor_custom_instructions_complex/src/lib.rs index 3d6e3f425e1..51de5cfeaea 100644 --- a/wasm/samples/executor_custom_instructions_complex/src/lib.rs +++ b/wasm/samples/executor_custom_instructions_complex/src/lib.rs @@ -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); } diff --git a/wasm/samples/executor_custom_instructions_simple/src/lib.rs b/wasm/samples/executor_custom_instructions_simple/src/lib.rs index 1f9203eb862..e9643967544 100644 --- a/wasm/samples/executor_custom_instructions_simple/src/lib.rs +++ b/wasm/samples/executor_custom_instructions_simple/src/lib.rs @@ -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); } diff --git a/wasm/samples/executor_with_custom_permission/src/lib.rs b/wasm/samples/executor_with_custom_permission/src/lib.rs index a55a985610f..2796728a7d2 100644 --- a/wasm/samples/executor_with_custom_permission/src/lib.rs +++ b/wasm/samples/executor_with_custom_permission/src/lib.rs @@ -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, From e3a40eaa2578ef10bbe38c5876dbecdead880a15 Mon Sep 17 00:00:00 2001 From: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:40:45 +0900 Subject: [PATCH 2/2] review: `::len` Signed-off-by: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> --- crates/iroha_data_model/src/query/builder.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/iroha_data_model/src/query/builder.rs b/crates/iroha_data_model/src/query/builder.rs index 95b9501af48..18131db47d1 100644 --- a/crates/iroha_data_model/src/query/builder.rs +++ b/crates/iroha_data_model/src/query/builder.rs @@ -132,9 +132,12 @@ where Vec: TryFrom, as TryFrom>::Error: core::fmt::Debug, { - #[expect(clippy::cast_possible_truncation)] 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") } }