Skip to content

Commit 7e79f10

Browse files
authored
Merge pull request #13 from dtolnay/self
Support arbitrary self types
2 parents 5ba252c + b5219b6 commit 7e79f10

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/expand.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ fn transform_block(context: Context, sig: &mut MethodSig, block: &mut Block, has
294294
};
295295
}
296296
},
297+
Some(FnArg::Captured(ArgCaptured {
298+
pat: Pat::Ident(arg),
299+
..
300+
})) => {
301+
if arg.ident == "self" {
302+
arg.ident = Ident::new("_self", arg.ident.span());
303+
}
304+
}
297305
_ => {}
298306
}
299307

tests/test.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,21 @@ mod issue9 {
158158
async fn f(_x: Self) {}
159159
}
160160
}
161+
162+
// https://github.com/dtolnay/async-trait/issues/11
163+
mod issue11 {
164+
use async_trait::async_trait;
165+
use std::sync::Arc;
166+
167+
#[async_trait]
168+
trait Issue11 {
169+
async fn example(self: Arc<Self>);
170+
}
171+
172+
struct Struct;
173+
174+
#[async_trait]
175+
impl Issue11 for Struct {
176+
async fn example(self: Arc<Self>) {}
177+
}
178+
}

0 commit comments

Comments
 (0)