From 5d6788cd6806a69143d33f72bba8f1220cb3dd97 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 28 Nov 2024 17:45:09 +0000 Subject: [PATCH] Align with the updated Rust (#3142) Fixes the code to satisfy `clippy`. Some Derivative annotations were replaced with custom implementation due to the following weird error, which I couldn't mute even with `#[allow(clippy::needless_lifetimes)]`. ``` 53 | #[derive(Clone, PartialEq, Eq, Hash, Default, Serialize, Derivative)] | ^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `-D clippy::needless-lifetimes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` = note: this error originates in the derive macro `Derivative` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- crates/app-data/src/app_data.rs | 2 +- crates/autopilot/src/infra/solvers/dto/solve.rs | 2 +- crates/chain/src/lib.rs | 2 +- crates/driver/src/tests/setup/mod.rs | 2 +- crates/driver/src/util/serialize/hex.rs | 4 ++-- crates/driver/src/util/serialize/u256.rs | 2 +- crates/model/src/order.rs | 10 ++-------- crates/model/src/quote.rs | 1 - crates/model/src/signature.rs | 2 +- crates/number/src/serialization.rs | 2 +- crates/shared/src/baseline_solver.rs | 2 +- .../shared/src/price_estimation/native_price_cache.rs | 2 +- crates/shared/src/trade_finding/mod.rs | 1 + crates/solver/src/liquidity/slippage.rs | 2 +- crates/solvers-dto/src/lib.rs | 4 ++-- 15 files changed, 17 insertions(+), 23 deletions(-) diff --git a/crates/app-data/src/app_data.rs b/crates/app-data/src/app_data.rs index 99a9d8b39a..c8cd70f5b5 100644 --- a/crates/app-data/src/app_data.rs +++ b/crates/app-data/src/app_data.rs @@ -175,7 +175,7 @@ impl<'de> Deserialize<'de> for OrderUid { D: Deserializer<'de>, { struct Visitor {} - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = OrderUid; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/crates/autopilot/src/infra/solvers/dto/solve.rs b/crates/autopilot/src/infra/solvers/dto/solve.rs index 3ec1de1ff5..a54c143f70 100644 --- a/crates/autopilot/src/infra/solvers/dto/solve.rs +++ b/crates/autopilot/src/infra/solvers/dto/solve.rs @@ -188,7 +188,7 @@ where { struct SolutionIdVisitor; - impl<'de> serde::de::Visitor<'de> for SolutionIdVisitor { + impl serde::de::Visitor<'_> for SolutionIdVisitor { type Value = u64; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/chain/src/lib.rs b/crates/chain/src/lib.rs index 6fdb43931e..d256fb6aaf 100644 --- a/crates/chain/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -129,7 +129,7 @@ impl<'de> Deserialize<'de> for Chain { { struct NetworkVisitor; - impl<'de> de::Visitor<'de> for NetworkVisitor { + impl de::Visitor<'_> for NetworkVisitor { type Value = Chain; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/driver/src/tests/setup/mod.rs b/crates/driver/src/tests/setup/mod.rs index 63458971b0..c418f08a26 100644 --- a/crates/driver/src/tests/setup/mod.rs +++ b/crates/driver/src/tests/setup/mod.rs @@ -1194,7 +1194,7 @@ impl<'a> Solve<'a> { } } -impl<'a> SolveOk<'a> { +impl SolveOk<'_> { fn solutions(&self) -> Vec { #[derive(serde::Deserialize)] struct Body { diff --git a/crates/driver/src/util/serialize/hex.rs b/crates/driver/src/util/serialize/hex.rs index f335cdbb1b..d7d5162fdd 100644 --- a/crates/driver/src/util/serialize/hex.rs +++ b/crates/driver/src/util/serialize/hex.rs @@ -11,7 +11,7 @@ impl<'de> DeserializeAs<'de, Vec> for Hex { fn deserialize_as>(deserializer: D) -> Result, D::Error> { struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = Vec; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -50,7 +50,7 @@ impl<'de, const N: usize> DeserializeAs<'de, [u8; N]> for Hex { result: [u8; N], } - impl<'de, const N: usize> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = [u8; N]; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/driver/src/util/serialize/u256.rs b/crates/driver/src/util/serialize/u256.rs index 851e9dc660..5653ada535 100644 --- a/crates/driver/src/util/serialize/u256.rs +++ b/crates/driver/src/util/serialize/u256.rs @@ -12,7 +12,7 @@ impl<'de> DeserializeAs<'de, eth::U256> for U256 { fn deserialize_as>(deserializer: D) -> Result { struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = eth::U256; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index f506e23f1e..0e2f6c86a4 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -1,5 +1,6 @@ //! Contains the order type as described by the specification with serialization //! as described by the openapi documentation. +#![allow(clippy::needless_lifetimes)] // todo: migrate from derivative to derive_more use { crate::{ @@ -819,7 +820,7 @@ impl<'de> Deserialize<'de> for OrderUid { D: Deserializer<'de>, { struct Visitor {} - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = OrderUid; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -1009,13 +1010,6 @@ impl BuyTokenDestination { } } -pub fn debug_app_data( - app_data: &[u8; 32], - formatter: &mut std::fmt::Formatter, -) -> Result<(), std::fmt::Error> { - formatter.write_fmt(format_args!("{:?}", H256(*app_data))) -} - pub fn debug_biguint_to_string( value: &BigUint, formatter: &mut std::fmt::Formatter, diff --git a/crates/model/src/quote.rs b/crates/model/src/quote.rs index 489e48c4bf..63d2409fea 100644 --- a/crates/model/src/quote.rs +++ b/crates/model/src/quote.rs @@ -184,7 +184,6 @@ impl Default for Validity { } /// Helper struct for `Validity` serialization. - impl<'de> Deserialize<'de> for Validity { fn deserialize(deserializer: D) -> Result where diff --git a/crates/model/src/signature.rs b/crates/model/src/signature.rs index d3477cd74a..5fce6e1976 100644 --- a/crates/model/src/signature.rs +++ b/crates/model/src/signature.rs @@ -385,7 +385,7 @@ impl<'de> Deserialize<'de> for EcdsaSignature { D: serde::Deserializer<'de>, { struct Visitor {} - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = EcdsaSignature; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/crates/number/src/serialization.rs b/crates/number/src/serialization.rs index 3f57cffa11..8d15613a12 100644 --- a/crates/number/src/serialization.rs +++ b/crates/number/src/serialization.rs @@ -37,7 +37,7 @@ where D: Deserializer<'de>, { struct Visitor {} - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = U256; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/crates/shared/src/baseline_solver.rs b/crates/shared/src/baseline_solver.rs index aadd8a10e1..d7802f05c6 100644 --- a/crates/shared/src/baseline_solver.rs +++ b/crates/shared/src/baseline_solver.rs @@ -39,7 +39,7 @@ pub struct Estimate<'a, V, L> { pub path: Vec<&'a L>, } -impl<'a, V, L: BaselineSolvable> Estimate<'a, V, L> { +impl Estimate<'_, V, L> { pub fn gas_cost(&self) -> usize { // This could be more accurate by actually simulating the settlement (since // different tokens might have more or less expensive transfer costs) diff --git a/crates/shared/src/price_estimation/native_price_cache.rs b/crates/shared/src/price_estimation/native_price_cache.rs index d2e18d8277..496f9340fd 100644 --- a/crates/shared/src/price_estimation/native_price_cache.rs +++ b/crates/shared/src/price_estimation/native_price_cache.rs @@ -115,7 +115,7 @@ impl Inner { &'a self, tokens: &'a [H160], max_age: Duration, - ) -> futures::stream::BoxStream<'_, (H160, NativePriceEstimateResult)> { + ) -> futures::stream::BoxStream<'a, (H160, NativePriceEstimateResult)> { let estimates = tokens.iter().map(move |token| async move { { // check if price is cached by now diff --git a/crates/shared/src/trade_finding/mod.rs b/crates/shared/src/trade_finding/mod.rs index 3e5e8bfdf4..2cb4cba961 100644 --- a/crates/shared/src/trade_finding/mod.rs +++ b/crates/shared/src/trade_finding/mod.rs @@ -1,5 +1,6 @@ //! A module for abstracting a component that can produce a quote with calldata //! for a specified token pair and amount. +#![allow(clippy::needless_lifetimes)] // todo: migrate from derivative to derive_more pub mod external; diff --git a/crates/solver/src/liquidity/slippage.rs b/crates/solver/src/liquidity/slippage.rs index 40188be299..0d2566fd47 100644 --- a/crates/solver/src/liquidity/slippage.rs +++ b/crates/solver/src/liquidity/slippage.rs @@ -22,7 +22,7 @@ pub struct SlippageContext<'a> { calculator: &'a SlippageCalculator, } -impl<'a> SlippageContext<'a> { +impl SlippageContext<'_> { /// Returns the external prices used for the slippage context. pub fn prices(&self) -> &ExternalPrices { self.prices diff --git a/crates/solvers-dto/src/lib.rs b/crates/solvers-dto/src/lib.rs index b5cbc5a0da..9606b4b0f1 100644 --- a/crates/solvers-dto/src/lib.rs +++ b/crates/solvers-dto/src/lib.rs @@ -19,7 +19,7 @@ mod serialize { fn deserialize_as>(deserializer: D) -> Result, D::Error> { struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = Vec; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -58,7 +58,7 @@ mod serialize { result: [u8; N], } - impl<'de, const N: usize> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = [u8; N]; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {