dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Upgrade from 0.1.42 to 0.1.43 triggers clippy::type_complexity #145

Closed djc closed 3 years ago

djc commented 3 years ago

I'm getting this:

warning: very complex type used. Consider factoring parts into `type` definitions
   --> bb8/src/api.rs:261:14
    |
261 |     async fn connect(&self) -> Result<Self::Connection, Self::Error>;
    |              ^^^^^^^
    |
    = note: `#[warn(clippy::type_complexity)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

for this trait definition in bb8:

/// A trait which provides connection-specific functionality.
#[async_trait]
pub trait ManageConnection: Sized + Send + Sync + 'static {
    /// The connection type this manager deals with.
    type Connection: Send + 'static;
    /// The error type returned by `Connection`s.
    type Error: fmt::Debug + Send + 'static;

    /// Attempts to create a new connection.
    async fn connect(&self) -> Result<Self::Connection, Self::Error>;
    /// Determines if the connection is still connected to the database.
    async fn is_valid(&self, conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error>;
    /// Synchronously determine if the connection is no longer usable, if possible.
    fn has_broken(&self, conn: &mut Self::Connection) -> bool;
}

Should I suppress this on my side, or is that something the async-trait macro could/should do?

dtolnay commented 3 years ago

The future coming out of async-trait is something like ::core::pin::Pin<Box<dyn ::core::future::Future<Output = Result<Self::Connection, Self::Error>> + ::core::marker::Send + 'async_trait>> which is indeed complex! Sorry about the breakage. This needs to be fixed in async-trait with a suppression because it isn't really the caller code's "fault".

dtolnay commented 3 years ago

I released 0.1.44 with a fix.

djc commented 3 years ago

Great, thanks for the quick response!