Skip to content

Commit

Permalink
Merge pull request #745 from EspressoSystems/ab/fix-clippy-warnings
Browse files Browse the repository at this point in the history
fix clippy warnings
  • Loading branch information
imabdulbasit authored Dec 4, 2024
2 parents d17f0d6 + d471d65 commit 811532b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 81 deletions.
24 changes: 16 additions & 8 deletions src/data_source/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ where
D: VersionedDataSource + Send,
U: Send + Sync,
{
type Transaction<'a> = D::Transaction<'a>
type Transaction<'a>
= D::Transaction<'a>
where
Self: 'a;

type ReadOnly<'a> = D::ReadOnly<'a>
type ReadOnly<'a>
= D::ReadOnly<'a>
where
Self: 'a;

Expand All @@ -144,22 +146,28 @@ where
Types: NodeType,
Payload<Types>: QueryablePayload<Types>,
{
type LeafRange<R> = D::LeafRange<R>
type LeafRange<R>
= D::LeafRange<R>
where
R: RangeBounds<usize> + Send;
type BlockRange<R> = D::BlockRange<R>
type BlockRange<R>
= D::BlockRange<R>
where
R: RangeBounds<usize> + Send;
type PayloadRange<R> = D::PayloadRange<R>
type PayloadRange<R>
= D::PayloadRange<R>
where
R: RangeBounds<usize> + Send;
type PayloadMetadataRange<R> = D::PayloadMetadataRange<R>
type PayloadMetadataRange<R>
= D::PayloadMetadataRange<R>
where
R: RangeBounds<usize> + Send;
type VidCommonRange<R> = D::VidCommonRange<R>
type VidCommonRange<R>
= D::VidCommonRange<R>
where
R: RangeBounds<usize> + Send;
type VidCommonMetadataRange<R> = D::VidCommonMetadataRange<R>
type VidCommonMetadataRange<R>
= D::VidCommonMetadataRange<R>
where
R: RangeBounds<usize> + Send;

Expand Down
30 changes: 20 additions & 10 deletions src/data_source/fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,22 +560,28 @@ where
for<'a> S::ReadOnly<'a>: AvailabilityStorage<Types> + NodeStorage<Types> + PrunedHeightStorage,
P: AvailabilityProvider<Types>,
{
type LeafRange<R> = BoxStream<'static, Fetch<LeafQueryData<Types>>>
type LeafRange<R>
= BoxStream<'static, Fetch<LeafQueryData<Types>>>
where
R: RangeBounds<usize> + Send;
type BlockRange<R> = BoxStream<'static, Fetch<BlockQueryData<Types>>>
type BlockRange<R>
= BoxStream<'static, Fetch<BlockQueryData<Types>>>
where
R: RangeBounds<usize> + Send;
type PayloadRange<R> = BoxStream<'static, Fetch<PayloadQueryData<Types>>>
type PayloadRange<R>
= BoxStream<'static, Fetch<PayloadQueryData<Types>>>
where
R: RangeBounds<usize> + Send;
type PayloadMetadataRange<R> = BoxStream<'static, Fetch<PayloadMetadata<Types>>>
type PayloadMetadataRange<R>
= BoxStream<'static, Fetch<PayloadMetadata<Types>>>
where
R: RangeBounds<usize> + Send;
type VidCommonRange<R> = BoxStream<'static, Fetch<VidCommonQueryData<Types>>>
type VidCommonRange<R>
= BoxStream<'static, Fetch<VidCommonQueryData<Types>>>
where
R: RangeBounds<usize> + Send;
type VidCommonMetadataRange<R> = BoxStream<'static, Fetch<VidCommonMetadata<Types>>>
type VidCommonMetadataRange<R>
= BoxStream<'static, Fetch<VidCommonMetadata<Types>>>
where
R: RangeBounds<usize> + Send;

Expand Down Expand Up @@ -715,10 +721,12 @@ where
S: VersionedDataSource + Send + Sync,
P: Send + Sync,
{
type Transaction<'a> = S::Transaction<'a>
type Transaction<'a>
= S::Transaction<'a>
where
Self: 'a;
type ReadOnly<'a> = S::ReadOnly<'a>
type ReadOnly<'a>
= S::ReadOnly<'a>
where
Self: 'a;

Expand Down Expand Up @@ -761,10 +769,12 @@ where
S: VersionedDataSource + Send + Sync,
P: Send + Sync,
{
type Transaction<'a> = S::Transaction<'a>
type Transaction<'a>
= S::Transaction<'a>
where
Self: 'a;
type ReadOnly<'a> = S::ReadOnly<'a>
type ReadOnly<'a>
= S::ReadOnly<'a>
where
Self: 'a;

Expand Down
6 changes: 4 additions & 2 deletions src/data_source/storage/fail_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ impl<S> VersionedDataSource for FailStorage<S>
where
S: VersionedDataSource,
{
type Transaction<'a> = Transaction<S::Transaction<'a>>
type Transaction<'a>
= Transaction<S::Transaction<'a>>
where
Self: 'a;
type ReadOnly<'a> = Transaction<S::ReadOnly<'a>>
type ReadOnly<'a>
= Transaction<S::ReadOnly<'a>>
where
Self: 'a;

Expand Down
10 changes: 6 additions & 4 deletions src/data_source/storage/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub trait Revert {
fn revert(&mut self);
}

impl<'a, Types> Revert for RwLockWriteGuard<'a, FileSystemStorageInner<Types>>
impl<Types> Revert for RwLockWriteGuard<'_, FileSystemStorageInner<Types>>
where
Types: NodeType,
Payload<Types>: QueryablePayload<Types>,
Expand All @@ -293,7 +293,7 @@ where
}
}

impl<'a, Types> Revert for RwLockReadGuard<'a, FileSystemStorageInner<Types>>
impl<Types> Revert for RwLockReadGuard<'_, FileSystemStorageInner<Types>>
where
Types: NodeType,
Payload<Types>: QueryablePayload<Types>,
Expand Down Expand Up @@ -357,10 +357,12 @@ impl<Types: NodeType> VersionedDataSource for FileSystemStorage<Types>
where
Payload<Types>: QueryablePayload<Types>,
{
type Transaction<'a> = Transaction<RwLockWriteGuard<'a, FileSystemStorageInner<Types>>>
type Transaction<'a>
= Transaction<RwLockWriteGuard<'a, FileSystemStorageInner<Types>>>
where
Self: 'a;
type ReadOnly<'a> = Transaction<RwLockReadGuard<'a, FileSystemStorageInner<Types>>>
type ReadOnly<'a>
= Transaction<RwLockReadGuard<'a, FileSystemStorageInner<Types>>>
where
Self: 'a;

Expand Down
12 changes: 3 additions & 9 deletions src/data_source/storage/ledger_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,7 @@ impl<T: Serialize + DeserializeOwned + Clone> LedgerLog<T> {
let len = store.iter().len();
tracing::info!("loading LedgerLog {}, len={}", file_pattern, len);

let cache_start = if len > cache_size {
len - cache_size
} else {
// If the cache is large enough to contain every object in storage, we start it at index
// 0 so that it does.
0
};
let cache_start = len.saturating_sub(cache_size);
let mut missing = 0;
let mut cache = store
.iter()
Expand Down Expand Up @@ -220,7 +214,7 @@ pub struct Iter<'a, T: Serialize + DeserializeOwned> {
store: append_log::Iter<'a, BincodeLoadStore<Option<T>>>,
}

impl<'a, T: Serialize + DeserializeOwned + Clone> Iterator for Iter<'a, T> {
impl<T: Serialize + DeserializeOwned + Clone> Iterator for Iter<'_, T> {
type Item = Option<T>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -264,7 +258,7 @@ impl<'a, T: Serialize + DeserializeOwned + Clone> Iterator for Iter<'a, T> {
}
}

impl<'a, T: Serialize + DeserializeOwned + Clone> ExactSizeIterator for Iter<'a, T> {}
impl<T: Serialize + DeserializeOwned + Clone> ExactSizeIterator for Iter<'_, T> {}

#[cfg(test)]
mod test {
Expand Down
38 changes: 24 additions & 14 deletions src/data_source/storage/no_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ pub struct Transaction<'a> {
}

impl VersionedDataSource for NoStorage {
type Transaction<'a> = Transaction<'a>
type Transaction<'a>
= Transaction<'a>
where
Self: 'a;
type ReadOnly<'a> = Transaction<'a>
type ReadOnly<'a>
= Transaction<'a>
where
Self: 'a;

Expand Down Expand Up @@ -97,7 +99,7 @@ impl PrunerConfig for NoStorage {}
impl PruneStorage for NoStorage {
type Pruner = ();
}
impl<'a> PrunedHeightStorage for Transaction<'a> {}
impl PrunedHeightStorage for Transaction<'_> {}

impl HasMetrics for NoStorage {
fn metrics(&self) -> &PrometheusMetrics {
Expand All @@ -106,7 +108,7 @@ impl HasMetrics for NoStorage {
}

#[async_trait]
impl<'a, Types: NodeType> AvailabilityStorage<Types> for Transaction<'a>
impl<Types: NodeType> AvailabilityStorage<Types> for Transaction<'_>
where
Payload<Types>: QueryablePayload<Types>,
{
Expand Down Expand Up @@ -240,7 +242,7 @@ where
}

#[async_trait]
impl<'a, Types: NodeType> NodeStorage<Types> for Transaction<'a>
impl<Types: NodeType> NodeStorage<Types> for Transaction<'_>
where
Payload<Types>: QueryablePayload<Types>,
{
Expand Down Expand Up @@ -462,10 +464,12 @@ pub mod testing {
// Now a lot of boilerplate to implement all teh traits for [`DataSource`], by dispatching each
// method to either variant.
impl VersionedDataSource for DataSource {
type Transaction<'a> = Transaction<'a, <SqlStorage as VersionedDataSource>::Transaction<'a>>
type Transaction<'a>
= Transaction<'a, <SqlStorage as VersionedDataSource>::Transaction<'a>>
where
Self: 'a;
type ReadOnly<'a> = Transaction<'a, <SqlStorage as VersionedDataSource>::ReadOnly<'a>>
type ReadOnly<'a>
= Transaction<'a, <SqlStorage as VersionedDataSource>::ReadOnly<'a>>
where
Self: 'a;

Expand Down Expand Up @@ -554,22 +558,28 @@ pub mod testing {

#[async_trait]
impl AvailabilityDataSource<MockTypes> for DataSource {
type LeafRange<R> = BoxStream<'static, Fetch<LeafQueryData<MockTypes>>>
type LeafRange<R>
= BoxStream<'static, Fetch<LeafQueryData<MockTypes>>>
where
R: RangeBounds<usize> + Send;
type BlockRange<R> = BoxStream<'static, Fetch<BlockQueryData<MockTypes>>>
type BlockRange<R>
= BoxStream<'static, Fetch<BlockQueryData<MockTypes>>>
where
R: RangeBounds<usize> + Send;
type PayloadRange<R> = BoxStream<'static, Fetch<PayloadQueryData<MockTypes>>>
type PayloadRange<R>
= BoxStream<'static, Fetch<PayloadQueryData<MockTypes>>>
where
R: RangeBounds<usize> + Send;
type PayloadMetadataRange<R> = BoxStream<'static, Fetch<PayloadMetadata<MockTypes>>>
type PayloadMetadataRange<R>
= BoxStream<'static, Fetch<PayloadMetadata<MockTypes>>>
where
R: RangeBounds<usize> + Send;
type VidCommonRange<R> = BoxStream<'static, Fetch<VidCommonQueryData<MockTypes>>>
type VidCommonRange<R>
= BoxStream<'static, Fetch<VidCommonQueryData<MockTypes>>>
where
R: RangeBounds<usize> + Send;
type VidCommonMetadataRange<R> = BoxStream<'static, Fetch<VidCommonMetadata<MockTypes>>>
type VidCommonMetadataRange<R>
= BoxStream<'static, Fetch<VidCommonMetadata<MockTypes>>>
where
R: RangeBounds<usize> + Send;

Expand Down Expand Up @@ -720,7 +730,7 @@ pub mod testing {
}

#[async_trait]
impl<'a, T> NodeStorage<MockTypes> for Transaction<'a, T>
impl<T> NodeStorage<MockTypes> for Transaction<'_, T>
where
T: NodeStorage<MockTypes> + Send,
{
Expand Down
6 changes: 4 additions & 2 deletions src/data_source/storage/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,12 @@ impl PruneStorage for SqlStorage {
}

impl VersionedDataSource for SqlStorage {
type Transaction<'a> = Transaction<Write>
type Transaction<'a>
= Transaction<Write>
where
Self: 'a;
type ReadOnly<'a> = Transaction<Read>
type ReadOnly<'a>
= Transaction<Read>
where
Self: 'a;

Expand Down
1 change: 0 additions & 1 deletion src/data_source/storage/sql/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
/// for<'a> i64: Type<DB> + Encode<'a, DB>,
/// {}
/// ```
#[cfg(feature = "embedded-db")]
pub type Db = sqlx::Sqlite;
#[cfg(not(feature = "embedded-db"))]
Expand Down
6 changes: 3 additions & 3 deletions src/data_source/storage/sql/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(super) struct Migrator<'a> {
}

#[async_trait]
impl<'a> AsyncTransaction for Migrator<'a> {
impl AsyncTransaction for Migrator<'_> {
type Error = sqlx::Error;

async fn execute(&mut self, queries: &[&str]) -> sqlx::Result<usize> {
Expand All @@ -38,7 +38,7 @@ impl<'a> AsyncTransaction for Migrator<'a> {
}

#[async_trait]
impl<'a> AsyncQuery<Vec<Migration>> for Migrator<'a> {
impl AsyncQuery<Vec<Migration>> for Migrator<'_> {
async fn query(&mut self, query: &str) -> sqlx::Result<Vec<Migration>> {
let mut tx = self.conn.begin().await?;

Expand Down Expand Up @@ -68,4 +68,4 @@ impl<'a> AsyncQuery<Vec<Migration>> for Migrator<'a> {
}
}

impl<'a> AsyncMigrate for Migrator<'a> {}
impl AsyncMigrate for Migrator<'_> {}
7 changes: 4 additions & 3 deletions src/data_source/storage/sql/queries.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_lifetimes)]
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the HotShot Query Service library.
//
Expand Down Expand Up @@ -81,9 +82,9 @@ pub(super) mod state;
/// ```
#[derive(Derivative, Default)]
#[derivative(Debug)]
pub struct QueryBuilder<'q> {
pub struct QueryBuilder<'a> {
#[derivative(Debug = "ignore")]
arguments: <Db as Database>::Arguments<'q>,
arguments: <Db as Database>::Arguments<'a>,
}

impl<'q> QueryBuilder<'q> {
Expand Down Expand Up @@ -113,7 +114,7 @@ impl<'q> QueryBuilder<'q> {
}
}

impl<'q> QueryBuilder<'q> {
impl QueryBuilder<'_> {
/// Construct a SQL `WHERE` clause which filters for a header exactly matching `id`.
pub fn header_where_clause<Types: NodeType>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/explorer/monetary_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
}
}

impl<'de> serde::de::Visitor<'de> for MonetaryValueVisitor {
impl serde::de::Visitor<'_> for MonetaryValueVisitor {
type Value = MonetaryValue;

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

0 comments on commit 811532b

Please sign in to comment.