From 2ac322ef91301719e6a8adb8d45b28a458fc7dd2 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 13 Sep 2023 13:59:14 +0200 Subject: [PATCH] Fix clippy warnings after toolchain bump --- contract-sdk-macros/src/error_derive.rs | 3 ++- runtime-sdk-macros/src/error_derive.rs | 8 ++++--- .../src/module_derive/method_handler.rs | 10 ++++----- runtime-sdk-macros/src/module_derive/mod.rs | 1 + runtime-sdk/modules/contracts/src/abi/gas.rs | 2 +- .../contracts/src/abi/oasis/validation.rs | 2 +- runtime-sdk/modules/contracts/src/types.rs | 2 +- runtime-sdk/modules/evm/src/lib.rs | 4 ++-- runtime-sdk/modules/evm/src/signed_call.rs | 2 +- runtime-sdk/modules/evm/src/types.rs | 6 ++---- runtime-sdk/src/context.rs | 21 ++++++++----------- runtime-sdk/src/modules/accounts/mod.rs | 2 +- runtime-sdk/src/modules/core/mod.rs | 6 +++--- .../runtimes/simple-keyvalue/src/keyvalue.rs | 2 +- 14 files changed, 35 insertions(+), 36 deletions(-) diff --git a/contract-sdk-macros/src/error_derive.rs b/contract-sdk-macros/src/error_derive.rs index 42956cdd58..a2bdb3bfd1 100644 --- a/contract-sdk-macros/src/error_derive.rs +++ b/contract-sdk-macros/src/error_derive.rs @@ -102,7 +102,8 @@ fn convert_variants( .fields .iter() .enumerate() - .filter_map(|(i, f)| (!f.attrs.is_empty()).then(|| (i, f.ident.clone()))); + .filter(|(_, f)| (!f.attrs.is_empty())) + .map(|(i, f)| (i, f.ident.clone())); let source = maybe_sources.next(); if maybe_sources.count() != 0 { variant_ident diff --git a/runtime-sdk-macros/src/error_derive.rs b/runtime-sdk-macros/src/error_derive.rs index 49c035ad32..ef0e0b269f 100644 --- a/runtime-sdk-macros/src/error_derive.rs +++ b/runtime-sdk-macros/src/error_derive.rs @@ -139,7 +139,8 @@ fn convert_variants( .fields .iter() .enumerate() - .filter_map(|(i, f)| (!f.attrs.is_empty()).then(|| (i, f.ident.clone()))); + .filter(|(_, f)| (!f.attrs.is_empty())) + .map(|(i, f)| (i, f.ident.clone())); let source = maybe_sources.next(); if maybe_sources.count() != 0 { variant_ident @@ -172,7 +173,8 @@ fn convert_variants( .fields .iter() .enumerate() - .filter_map(|(i, f)| (i != field_index).then(|| { + .filter(|(i, _)| i != &field_index) + .map(|(i, f)| { let pat = match f.ident { Some(ref ident) => Member::Named(ident.clone()), None => Member::Unnamed(Index { @@ -184,7 +186,7 @@ fn convert_variants( let binding = quote!( #pat: #ident, ); binding - })); + }); let non_source_field_bindings = non_source_fields.clone(); let source = quote!(source); diff --git a/runtime-sdk-macros/src/module_derive/method_handler.rs b/runtime-sdk-macros/src/module_derive/method_handler.rs index fb7343e779..99f4019db2 100644 --- a/runtime-sdk-macros/src/module_derive/method_handler.rs +++ b/runtime-sdk-macros/src/module_derive/method_handler.rs @@ -60,11 +60,11 @@ impl super::Deriver for DeriveMethodHandler { } let prefetch_impl = { - let (handler_names, handler_idents) = filter_by_kind(&handlers, HandlerKind::Prefetch); + let (handler_names, handler_idents) = filter_by_kind(handlers, HandlerKind::Prefetch); // Find call handlers; for every call handler without a corresponding prefetch handler, we'll // generate a dummy prefetch handler. - let (call_handler_names, _) = filter_by_kind(&handlers, HandlerKind::Call); + let (call_handler_names, _) = filter_by_kind(handlers, HandlerKind::Call); let handler_names_without_impl: Vec<&syn::Expr> = call_handler_names .iter() .filter(|n| !handler_names.contains(n)) @@ -100,7 +100,7 @@ impl super::Deriver for DeriveMethodHandler { }; let dispatch_call_impl = { - let (handler_names, handler_idents) = filter_by_kind(&handlers, HandlerKind::Call); + let (handler_names, handler_idents) = filter_by_kind(handlers, HandlerKind::Call); if handler_names.is_empty() { quote! {} @@ -131,7 +131,7 @@ impl super::Deriver for DeriveMethodHandler { }; let dispatch_query_impl = { - let (handler_names, handler_idents) = filter_by_kind(&handlers, HandlerKind::Query); + let (handler_names, handler_idents) = filter_by_kind(handlers, HandlerKind::Query); if handler_names.is_empty() { quote! { @@ -167,7 +167,7 @@ impl super::Deriver for DeriveMethodHandler { let dispatch_message_result_impl = { let (handler_names, handler_idents) = - filter_by_kind(&handlers, HandlerKind::MessageResult); + filter_by_kind(handlers, HandlerKind::MessageResult); if handler_names.is_empty() { quote! {} diff --git a/runtime-sdk-macros/src/module_derive/mod.rs b/runtime-sdk-macros/src/module_derive/mod.rs index 7e4467cbd4..9a4cbbeaad 100644 --- a/runtime-sdk-macros/src/module_derive/mod.rs +++ b/runtime-sdk-macros/src/module_derive/mod.rs @@ -74,6 +74,7 @@ pub fn derive_module(impl_block: syn::ItemImpl) -> TokenStream { trait Deriver { fn preprocess(&mut self, item: syn::ImplItem) -> Option; + #[allow(clippy::borrowed_box)] fn derive(&mut self, generics: &syn::Generics, ty: &Box) -> TokenStream; } diff --git a/runtime-sdk/modules/contracts/src/abi/gas.rs b/runtime-sdk/modules/contracts/src/abi/gas.rs index c26451b337..6214b66eba 100644 --- a/runtime-sdk/modules/contracts/src/abi/gas.rs +++ b/runtime-sdk/modules/contracts/src/abi/gas.rs @@ -211,7 +211,7 @@ impl MeteredBlocks { } } -fn determine_metered_blocks(func: &mut LocalFunction) -> BTreeMap> { +fn determine_metered_blocks(func: &LocalFunction) -> BTreeMap> { // NOTE: This is based on walrus::ir::dfs_in_order but we need more information. let mut blocks = MeteredBlocks::default(); diff --git a/runtime-sdk/modules/contracts/src/abi/oasis/validation.rs b/runtime-sdk/modules/contracts/src/abi/oasis/validation.rs index 84efcb340e..e3317944fd 100644 --- a/runtime-sdk/modules/contracts/src/abi/oasis/validation.rs +++ b/runtime-sdk/modules/contracts/src/abi/oasis/validation.rs @@ -411,7 +411,7 @@ impl<'instr> Visitor<'instr> for FloatScanner { impl OasisV1 { pub(super) fn validate_module( &self, - module: &mut Module, + module: &Module, params: &Parameters, ) -> Result { // Verify that all required exports are there. diff --git a/runtime-sdk/modules/contracts/src/types.rs b/runtime-sdk/modules/contracts/src/types.rs index 6e11be3843..a5be637391 100644 --- a/runtime-sdk/modules/contracts/src/types.rs +++ b/runtime-sdk/modules/contracts/src/types.rs @@ -24,7 +24,7 @@ pub enum Policy { impl Policy { /// Enforce the given policy by returning an error if the policy is not satisfied by the passed /// transaction context. - pub fn enforce(&self, ctx: &mut C) -> Result<(), Error> { + pub fn enforce(&self, ctx: &C) -> Result<(), Error> { match self { // Nobody is allowed to perform the action. Policy::Nobody => Err(Error::Forbidden), diff --git a/runtime-sdk/modules/evm/src/lib.rs b/runtime-sdk/modules/evm/src/lib.rs index bd5c1f52d9..836ffb22b5 100644 --- a/runtime-sdk/modules/evm/src/lib.rs +++ b/runtime-sdk/modules/evm/src/lib.rs @@ -539,7 +539,7 @@ impl Module { Ok(exit_value) } - fn derive_caller(ctx: &mut C) -> Result + fn derive_caller(ctx: &C) -> Result where C: TxContext, { @@ -590,7 +590,7 @@ impl Module { } fn decode_simulate_call_query( - ctx: &mut C, + ctx: &C, call: types::SimulateCallQuery, ) -> Result<(types::SimulateCallQuery, callformat::Metadata), Error> { if !Cfg::CONFIDENTIAL { diff --git a/runtime-sdk/modules/evm/src/signed_call.rs b/runtime-sdk/modules/evm/src/signed_call.rs index 163d74d37d..6f81e7ab4d 100644 --- a/runtime-sdk/modules/evm/src/signed_call.rs +++ b/runtime-sdk/modules/evm/src/signed_call.rs @@ -19,7 +19,7 @@ use crate::{ /// /// See [`crate::types::SignedSimulateCallEnvelope`] for details on the signature format. pub(crate) fn verify( - ctx: &mut C, + ctx: &C, query: SimulateCallQuery, leash: Leash, mut signature: [u8; 65], diff --git a/runtime-sdk/modules/evm/src/types.rs b/runtime-sdk/modules/evm/src/types.rs index b1809fe426..6898f66bab 100644 --- a/runtime-sdk/modules/evm/src/types.rs +++ b/runtime-sdk/modules/evm/src/types.rs @@ -108,15 +108,13 @@ pub struct Leash { // // Thanks to Nick for providing the fancy macros below :) -// This `mod` exists solely to place an `#[allow(warnings)]` around the generated code. -#[allow(warnings)] +// This `mod` exists solely to place an `#[allow(...)]` around the generated code. +#[allow(clippy::assign_op_pattern, clippy::incorrect_clone_impl_on_copy_type)] mod eth { use std::convert::TryFrom; use thiserror::Error; - use super::*; - #[derive(Error, Debug)] pub enum NoError {} diff --git a/runtime-sdk/src/context.rs b/runtime-sdk/src/context.rs index e4b21487b7..58b641dadc 100644 --- a/runtime-sdk/src/context.rs +++ b/runtime-sdk/src/context.rs @@ -74,7 +74,7 @@ impl State { /// Merge a different state into this state. pub fn merge_from(&mut self, other: State) { for (key, event) in other.events { - let events = self.events.entry(key).or_insert_with(Vec::new); + let events = self.events.entry(key).or_default(); events.extend(event); } @@ -709,18 +709,18 @@ impl<'a, R: runtime::Runtime> Context for RuntimeBatchContext<'a, R> { fn emit_event(&mut self, event: E) { let etag = event.into_event_tag(); - let tag = self.block_etags.entry(etag.key).or_insert_with(Vec::new); + let tag = self.block_etags.entry(etag.key).or_default(); tag.push(etag.value); } fn emit_etag(&mut self, etag: EventTag) { - let tag = self.block_etags.entry(etag.key).or_insert_with(Vec::new); + let tag = self.block_etags.entry(etag.key).or_default(); tag.push(etag.value); } fn emit_etags(&mut self, etags: EventTags) { for (key, val) in etags { - let tag = self.block_etags.entry(key).or_insert_with(Vec::new); + let tag = self.block_etags.entry(key).or_default(); tag.extend(val) } } @@ -941,18 +941,18 @@ impl<'round, 'store, R: runtime::Runtime> Context for RuntimeTxContext<'round, ' fn emit_event(&mut self, event: E) { let etag = event.into_event_tag(); - let tag = self.etags.entry(etag.key).or_insert_with(Vec::new); + let tag = self.etags.entry(etag.key).or_default(); tag.push(etag.value); } fn emit_etag(&mut self, etag: EventTag) { - let tag = self.etags.entry(etag.key).or_insert_with(Vec::new); + let tag = self.etags.entry(etag.key).or_default(); tag.push(etag.value); } fn emit_etags(&mut self, etags: EventTags) { for (key, val) in etags { - let tag = self.etags.entry(key).or_insert_with(Vec::new); + let tag = self.etags.entry(key).or_default(); tag.extend(val) } } @@ -964,7 +964,7 @@ impl<'round, 'store, R: runtime::Runtime> Context for RuntimeTxContext<'round, ' fn commit(mut self) -> State { // Merge unconditional events into regular events on success. for (key, val) in self.etags_unconditional { - let tag = self.etags.entry(key).or_insert_with(Vec::new); + let tag = self.etags.entry(key).or_default(); tag.extend(val) } @@ -1085,10 +1085,7 @@ impl TxContext for RuntimeTxContext<'_, '_, R> { fn emit_unconditional_event(&mut self, event: E) { let etag = event.into_event_tag(); - let tag = self - .etags_unconditional - .entry(etag.key) - .or_insert_with(Vec::new); + let tag = self.etags_unconditional.entry(etag.key).or_default(); tag.push(etag.value); } } diff --git a/runtime-sdk/src/modules/accounts/mod.rs b/runtime-sdk/src/modules/accounts/mod.rs index 7e7cea6301..a27f7f8f34 100644 --- a/runtime-sdk/src/modules/accounts/mod.rs +++ b/runtime-sdk/src/modules/accounts/mod.rs @@ -388,7 +388,7 @@ impl Module { let den = &addrden.1; // Fetch existing account's balances or insert blank ones. - let addr_bals = b.entry(*addr).or_insert_with(BTreeMap::new); + let addr_bals = b.entry(*addr).or_default(); // Add to given denomination's balance or insert it if new. addr_bals diff --git a/runtime-sdk/src/modules/core/mod.rs b/runtime-sdk/src/modules/core/mod.rs index 8dff159a99..f66bf7ad81 100644 --- a/runtime-sdk/src/modules/core/mod.rs +++ b/runtime-sdk/src/modules/core/mod.rs @@ -862,7 +862,7 @@ impl Module { } impl Module { - fn get_local_min_gas_price(ctx: &mut C, denom: &token::Denomination) -> u128 { + fn get_local_min_gas_price(ctx: &C, denom: &token::Denomination) -> u128 { #[allow(clippy::borrow_interior_mutable_const)] ctx.local_config(MODULE_NAME) .as_ref() @@ -871,14 +871,14 @@ impl Module { .unwrap_or_default() } - fn get_local_max_estimated_gas(ctx: &mut C) -> u64 { + fn get_local_max_estimated_gas(ctx: &C) -> u64 { ctx.local_config(MODULE_NAME) .as_ref() .map(|cfg: &LocalConfig| cfg.max_estimated_gas) .unwrap_or_default() } - fn enforce_min_gas_price(ctx: &mut C, call: &Call) -> Result<(), Error> { + fn enforce_min_gas_price(ctx: &C, call: &Call) -> Result<(), Error> { // If the method is exempt from min gas price requirements, checks always pass. #[allow(clippy::borrow_interior_mutable_const)] if Cfg::MIN_GAS_PRICE_EXEMPT_METHODS.contains(call.method.as_str()) { diff --git a/tests/runtimes/simple-keyvalue/src/keyvalue.rs b/tests/runtimes/simple-keyvalue/src/keyvalue.rs index cd9d1600c0..40afa1dd06 100644 --- a/tests/runtimes/simple-keyvalue/src/keyvalue.rs +++ b/tests/runtimes/simple-keyvalue/src/keyvalue.rs @@ -290,7 +290,7 @@ impl Module { } } - fn get_key_pair(ctx: &mut C, id: &[u8]) -> Result { + fn get_key_pair(ctx: &C, id: &[u8]) -> Result { let kid = get_key_pair_id([id]); let kmgr = ctx .key_manager()