Repository: dtolnay/async-trait (rust)

Issue:
Unable to call `Self` in blanket implementation
I think this is a bug, sorry if it's not.

### Problem

When creating a blanket impl, e.g. `impl<T: A> B for T`, if you trying to call a `fn` on `Self` it doesn't work:

```rs
use async_trait::async_trait;

#[async_trait]
trait A {
    async fn a();
}

trait B {
    fn b();
}

#[async_trait]
impl<T: B> A for T {
    async fn a() {
        Self::b();
    }
}
```

```
error[E0276]: impl has stricter requirements than trait
  --> src/lib.rs:12:1
   |
5  |     async fn a();
   |     ------------- definition of `a` from trait
...
12 | #[async_trait]
   | ^^^^^^^^^^^^^^ impl has extra requirement `T: 'async_trait`
   |
   = note: this error originates in the attribute macro `async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Same problem even if `B` has `#[async_trait]` (with or without `B::b()` being `async`).

### Expected

I feel like this should work because it works when not using `async`:

```rs
trait A {
    fn a();
}

trait B {
    fn b();
}

impl<T: B> A for T {
    fn a() {
        Self::b();
    }
}
```

### Workaround

I did figure out a workaround (halfway through writing this :sweat_smile:), which is to use `T` instead of `Self`, so I don't think this issue is high priority, but I figured I should still report it (and share the workaround).

```rs
use async_trait::async_trait;

#[async_trait]
trait A {
    async fn a();
}

trait B {
    fn b();
}

#[async_trait]
impl<T: B> A for T {
    async fn a() {
        T::b();
    }
}
```

Pull request:
Omit `Self: 'async_trait` bound in impl when not needed by signature
Fixes #283.

Patch:
diff --git a/src/expand.rs b/src/expand.rs
index df02106..6546769 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -99,7 +99,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
                     ImplItem::Fn(method) if method.sig.asyncness.is_some() => {
                         let sig = &mut method.sig;
                         let block = &mut method.block;
-                        let has_self = has_self_in_sig(sig) || has_self_in_block(block);
+                        let has_self = has_self_in_sig(sig);
                         transform_block(context, sig, block);
                         transform_sig(context, sig, has_self, false, is_local);
                         method.attrs.push(lint_suppress_with_body());


Test patch:
diff --git a/tests/test.rs b/tests/test.rs
index 5d1c549..89c848b 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1683,3 +1683,23 @@ pub mod issue281 {
         }
     }
 }
+
+pub mod issue283 {
+    use async_trait::async_trait;
+
+    #[async_trait]
+    pub trait Trait {
+        async fn a();
+    }
+
+    pub trait Bound {
+        fn b();
+    }
+
+    #[async_trait]
+    impl<T: Bound> Trait for T {
+        async fn a() {
+            Self::b();
+        }
+    }
+}