Skip to content

Commit

Permalink
Propagate the span of self argument to inner function call
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jun 8, 2020
1 parent 5220bbd commit 1b8cec0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn transform_block(

let inner = format_ident!("__{}", sig.ident);
let args = sig.inputs.iter().enumerate().map(|(i, arg)| match arg {
FnArg::Receiver(_) => quote!(self),
FnArg::Receiver(Receiver { self_token, .. }) => quote!(#self_token),
FnArg::Typed(arg) => {
if let Pat::Ident(PatIdent { ident, .. }) = &*arg.pat {
quote!(#ident)
Expand Down
45 changes: 42 additions & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,33 @@ pub mod issue45 {
pub mod issue46 {
use async_trait::async_trait;

macro_rules! implement_commands {
macro_rules! implement_commands_workaround {
($tyargs:tt : $ty:tt) => {
#[async_trait]
pub trait AsyncCommands: Sized {
pub trait AsyncCommands1: Sized {
async fn f<$tyargs: $ty>(&mut self, x: $tyargs) {
self.f(x).await
}
}
};
}

implement_commands!(K: Send);
implement_commands_workaround!(K: Send);

macro_rules! implement_commands {
(
$tyargs:ident : $ty:ident
) => {
#[async_trait]
pub trait AsyncCommands2: Sized {
async fn f<$tyargs: $ty>(&mut self, x: $tyargs) {
self.f(x).await
}
}
};
}

implement_commands! { K: Send }
}

// https://github.com/dtolnay/async-trait/issues/53
Expand Down Expand Up @@ -867,3 +882,27 @@ pub mod issue92 {
}
}
}

mod issue104 {
use async_trait::async_trait;

#[async_trait]
trait T1 {
async fn id(&self) -> i32;
}

macro_rules! impl_t1 {
($ty: ty, $id: expr) => {
#[async_trait]
impl T1 for $ty {
async fn id(&self) -> i32 {
$id
}
}
};
}

struct Foo;

impl_t1!(Foo, 1);
}

0 comments on commit 1b8cec0

Please sign in to comment.