dtolnay / async-trait

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

Elided lifetimes clippy error appeared between 0.1.31 and 0.1.35 #110

Closed itmecho closed 4 years ago

itmecho commented 4 years ago

I have a Cargo.lock file which has async-trait locked to version 0.1.31 but it's not committed. When I run clippy, I get no error. If I remove that lock file and run clippy again, cargo downloads 0.1.35 and I get an error about needless explicit lifetimes.

Trait

#[async_trait::async_trait]
pub trait Loader {
    async fn load(&self, key: &str) -> Result<String>;
}

Implementation

#[async_trait::async_trait]
impl crate::Loader for AwsEc2MetadataLoader<'_> {
    async fn load(&self, key: &str) -> Result<String> {
        get_metadata_value(self.metadata_url, key).await
    }
}

Clippy error:

$ cargo clippy -- -D warnings
...
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
  --> src/loader/awsec2metadata.rs:58:5
   |
58 |     async fn load(&self, key: &str) -> Result<String> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D clippy::needless-lifetimes` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
...

If I change the method signature in the implementation to the following, the error goes away. From the README, it seems like this shouldn't be necessary?

    async fn load(&self, key: &'_ str) -> Result<String> {
itmecho commented 4 years ago

OK, I set the version to =0.1.34 and rerun clippy and the error isn't there so it must be in the latest release.

I have also just updated to rust 1.44.1 but it's still happening so I'm assuming it isn't related to https://github.com/rust-lang/rust-clippy/issues/5356

dtolnay commented 4 years ago

Thanks! Fixed in 0.1.36.

itmecho commented 4 years ago

Thanks for the speedy fix!