From 573093ab593394b2723a809cd6fe547b7e78ab5d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 15 Sep 2019 23:00:49 -0700 Subject: [PATCH] Support Self used as expr inside trait method body --- src/receiver.rs | 5 +++++ tests/test.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/receiver.rs b/src/receiver.rs index 29c610a..51a3e60 100644 --- a/src/receiver.rs +++ b/src/receiver.rs @@ -19,6 +19,11 @@ pub fn has_self_in_block(block: &mut Block) -> bool { struct HasSelf(bool); impl VisitMut for HasSelf { + fn visit_expr_path_mut(&mut self, expr: &mut ExprPath) { + self.0 |= expr.path.segments[0].ident == "Self"; + visit_mut::visit_expr_path_mut(self, expr); + } + fn visit_type_path_mut(&mut self, ty: &mut TypePath) { self.0 |= ty.path.segments[0].ident == "Self"; visit_mut::visit_type_path_mut(self, ty); diff --git a/tests/test.rs b/tests/test.rs index fe323ce..6fd5f62 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -341,3 +341,22 @@ mod issue28 { async fn h(); // do not chain } } + +// https://github.com/dtolnay/async-trait/issues/31 +pub mod issue31 { + use async_trait::async_trait; + + pub struct Struct<'a> { + pub name: &'a str, + } + + #[async_trait] + pub trait Trait<'a> { + async fn hello(thing: Struct<'a>) -> String; + async fn hello_twice(one: Struct<'a>, two: Struct<'a>) -> String { + let str1 = Self::hello(one).await; + let str2 = Self::hello(two).await; + str1 + &str2 + } + } +}