Skip to content

Commit ad14dee

Browse files
authored
Merge pull request #32 from dtolnay/self
Support Self used as expr inside trait method body
2 parents e6b2cd8 + 573093a commit ad14dee

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/receiver.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pub fn has_self_in_block(block: &mut Block) -> bool {
1919
struct HasSelf(bool);
2020

2121
impl VisitMut for HasSelf {
22+
fn visit_expr_path_mut(&mut self, expr: &mut ExprPath) {
23+
self.0 |= expr.path.segments[0].ident == "Self";
24+
visit_mut::visit_expr_path_mut(self, expr);
25+
}
26+
2227
fn visit_type_path_mut(&mut self, ty: &mut TypePath) {
2328
self.0 |= ty.path.segments[0].ident == "Self";
2429
visit_mut::visit_type_path_mut(self, ty);

tests/test.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,22 @@ mod issue28 {
341341
async fn h(); // do not chain
342342
}
343343
}
344+
345+
// https://github.com/dtolnay/async-trait/issues/31
346+
pub mod issue31 {
347+
use async_trait::async_trait;
348+
349+
pub struct Struct<'a> {
350+
pub name: &'a str,
351+
}
352+
353+
#[async_trait]
354+
pub trait Trait<'a> {
355+
async fn hello(thing: Struct<'a>) -> String;
356+
async fn hello_twice(one: Struct<'a>, two: Struct<'a>) -> String {
357+
let str1 = Self::hello(one).await;
358+
let str2 = Self::hello(two).await;
359+
str1 + &str2
360+
}
361+
}
362+
}

0 commit comments

Comments
 (0)