Skip to content

Commit

Permalink
Align with the updated Rust (#3142)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
squadgazzz authored Nov 28, 2024
1 parent b5fa428 commit 5d6788c
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/app-data/src/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/infra/solvers/dto/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ impl<'a> Solve<'a> {
}
}

impl<'a> SolveOk<'a> {
impl SolveOk<'_> {
fn solutions(&self) -> Vec<serde_json::Value> {
#[derive(serde::Deserialize)]
struct Body {
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/util/serialize/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'de> DeserializeAs<'de, Vec<u8>> for Hex {
fn deserialize_as<D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, D::Error> {
struct Visitor;

impl<'de> de::Visitor<'de> for Visitor {
impl de::Visitor<'_> for Visitor {
type Value = Vec<u8>;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -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<N> {
impl<const N: usize> de::Visitor<'_> for Visitor<N> {
type Value = [u8; N];

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/util/serialize/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<'de> DeserializeAs<'de, eth::U256> for U256 {
fn deserialize_as<D: Deserializer<'de>>(deserializer: D) -> Result<eth::U256, D::Error> {
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 {
Expand Down
10 changes: 2 additions & 8 deletions crates/model/src/order.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/model/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl Default for Validity {
}

/// Helper struct for `Validity` serialization.
impl<'de> Deserialize<'de> for Validity {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
2 changes: 1 addition & 1 deletion crates/model/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/number/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/baseline_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V, L: BaselineSolvable> 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)
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/price_estimation/native_price_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/shared/src/trade_finding/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/solver/src/liquidity/slippage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/solvers-dto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod serialize {
fn deserialize_as<D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, D::Error> {
struct Visitor;

impl<'de> de::Visitor<'de> for Visitor {
impl de::Visitor<'_> for Visitor {
type Value = Vec<u8>;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -58,7 +58,7 @@ mod serialize {
result: [u8; N],
}

impl<'de, const N: usize> de::Visitor<'de> for Visitor<N> {
impl<const N: usize> de::Visitor<'_> for Visitor<N> {
type Value = [u8; N];

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down

0 comments on commit 5d6788c

Please sign in to comment.