Skip to content

Commit

Permalink
Fix clippy warnings after toolchain bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Sep 13, 2023
1 parent 6b36a07 commit 3a9efd6
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 38 deletions.
3 changes: 2 additions & 1 deletion contract-sdk-macros/src/error_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions runtime-sdk-macros/src/error_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions runtime-sdk-macros/src/module_derive/method_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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! {}
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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! {}
Expand Down
1 change: 1 addition & 0 deletions runtime-sdk-macros/src/module_derive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub fn derive_module(impl_block: syn::ItemImpl) -> TokenStream {
trait Deriver {
fn preprocess(&mut self, item: syn::ImplItem) -> Option<syn::ImplItem>;

#[allow(clippy::borrowed_box)]
fn derive(&mut self, generics: &syn::Generics, ty: &Box<syn::Type>) -> TokenStream;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/modules/contracts/src/abi/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl MeteredBlocks {
}
}

fn determine_metered_blocks(func: &mut LocalFunction) -> BTreeMap<InstrSeqId, Vec<MeteredBlock>> {
fn determine_metered_blocks(func: &LocalFunction) -> BTreeMap<InstrSeqId, Vec<MeteredBlock>> {
// NOTE: This is based on walrus::ir::dfs_in_order but we need more information.

let mut blocks = MeteredBlocks::default();
Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/modules/contracts/src/abi/oasis/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<'instr> Visitor<'instr> for FloatScanner {
impl<Cfg: Config> OasisV1<Cfg> {
pub(super) fn validate_module(
&self,
module: &mut Module,
module: &Module,
params: &Parameters,
) -> Result<Info, Error> {
// Verify that all required exports are there.
Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/modules/contracts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: TxContext>(&self, ctx: &mut C) -> Result<(), Error> {
pub fn enforce<C: TxContext>(&self, ctx: &C) -> Result<(), Error> {
match self {
// Nobody is allowed to perform the action.
Policy::Nobody => Err(Error::Forbidden),
Expand Down
4 changes: 2 additions & 2 deletions runtime-sdk/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl<Cfg: Config> Module<Cfg> {
Ok(exit_value)
}

fn derive_caller<C>(ctx: &mut C) -> Result<H160, Error>
fn derive_caller<C>(ctx: &C) -> Result<H160, Error>
where
C: TxContext,
{
Expand Down Expand Up @@ -590,7 +590,7 @@ impl<Cfg: Config> Module<Cfg> {
}

fn decode_simulate_call_query<C: Context>(
ctx: &mut C,
ctx: &C,
call: types::SimulateCallQuery,
) -> Result<(types::SimulateCallQuery, callformat::Metadata), Error> {
if !Cfg::CONFIDENTIAL {
Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/modules/evm/src/signed_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
///
/// See [`crate::types::SignedSimulateCallEnvelope`] for details on the signature format.
pub(crate) fn verify<C: Context, Cfg: Config>(
ctx: &mut C,
ctx: &C,
query: SimulateCallQuery,
leash: Leash,
mut signature: [u8; 65],
Expand Down
6 changes: 2 additions & 4 deletions runtime-sdk/modules/evm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
21 changes: 9 additions & 12 deletions runtime-sdk/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -709,18 +709,18 @@ impl<'a, R: runtime::Runtime> Context for RuntimeBatchContext<'a, R> {

fn emit_event<E: 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();

Check warning on line 717 in runtime-sdk/src/context.rs

View check run for this annotation

Codecov / codecov/patch

runtime-sdk/src/context.rs#L717

Added line #L717 was not covered by tests
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)
}
}
Expand Down Expand Up @@ -941,18 +941,18 @@ impl<'round, 'store, R: runtime::Runtime> Context for RuntimeTxContext<'round, '

fn emit_event<E: 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)
}
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -1085,10 +1085,7 @@ impl<R: runtime::Runtime> TxContext for RuntimeTxContext<'_, '_, R> {

fn emit_unconditional_event<E: 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/src/modules/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions runtime-sdk/src/modules/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl<Cfg: Config> Module<Cfg> {
}

impl<Cfg: Config> Module<Cfg> {
fn get_local_min_gas_price<C: Context>(ctx: &mut C, denom: &token::Denomination) -> u128 {
fn get_local_min_gas_price<C: Context>(ctx: &C, denom: &token::Denomination) -> u128 {
#[allow(clippy::borrow_interior_mutable_const)]
ctx.local_config(MODULE_NAME)
.as_ref()
Expand All @@ -871,14 +871,14 @@ impl<Cfg: Config> Module<Cfg> {
.unwrap_or_default()
}

fn get_local_max_estimated_gas<C: Context>(ctx: &mut C) -> u64 {
fn get_local_max_estimated_gas<C: Context>(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<C: TxContext>(ctx: &mut C, call: &Call) -> Result<(), Error> {
fn enforce_min_gas_price<C: TxContext>(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()) {
Expand Down
8 changes: 6 additions & 2 deletions tests/contracts/hello/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl sdk::Contract for HelloWorld {
) -> Result<Option<Self::Response>, Error> {
// This method is called to handle any replies for emitted messages.
match reply {
Reply::Call { id, result, .. } if id == 0 => {
Reply::Call { id: 0, result, .. } => {
match result {
CallResult::Failed { module, code } => {
// Propagate all failures.
Expand All @@ -490,7 +490,11 @@ impl sdk::Contract for HelloWorld {
}
}
}
Reply::Call { id, result, data } if id == 42 => {
Reply::Call {
id: 42,
result,
data,
} => {
let data = cbor::from_value(data.unwrap()).unwrap();

let result: InstantiateResult = match result {
Expand Down
2 changes: 1 addition & 1 deletion tests/runtimes/simple-keyvalue/src/keyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Module {
}
}

fn get_key_pair<C: Context>(ctx: &mut C, id: &[u8]) -> Result<KeyPair, Error> {
fn get_key_pair<C: Context>(ctx: &C, id: &[u8]) -> Result<KeyPair, Error> {
let kid = get_key_pair_id([id]);
let kmgr = ctx
.key_manager()
Expand Down

0 comments on commit 3a9efd6

Please sign in to comment.