Skip to content

Commit

Permalink
Merge pull request #32 from dtolnay/self
Browse files Browse the repository at this point in the history
Support Self used as expr inside trait method body
  • Loading branch information
dtolnay authored Sep 16, 2019
2 parents e6b2cd8 + 573093a commit ad14dee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit ad14dee

Please sign in to comment.