Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the span of self argument #105

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}