Skip to content

Commit 99cff88

Browse files
authored
Merge pull request #98 from makcandrov/main
feat: support async traits
2 parents 611a100 + e96da34 commit 99cff88

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

src/gen.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,29 +706,31 @@ fn gen_method_item(
706706
// Generate the body of the function. This mainly depends on the self type,
707707
// but also on the proxy type.
708708
let fn_name = &sig.ident;
709+
let await_token = sig.asyncness.map(|_| quote! { .await });
710+
709711
let body = match self_arg {
710712
// Fn proxy types get a special treatment
711713
_ if proxy_type.is_fn() => {
712-
quote! { ({self})(#args) }
714+
quote! { ({self})(#args) #await_token }
713715
}
714716

715717
// No receiver
716718
SelfType::None => {
717719
// The proxy type is a reference, smart pointer or Box.
718-
quote! { #proxy_ty_param::#fn_name #generic_types(#args) }
720+
quote! { #proxy_ty_param::#fn_name #generic_types(#args) #await_token }
719721
}
720722

721723
// Receiver `self` (by value)
722724
SelfType::Value => {
723725
// The proxy type is a Box.
724-
quote! { #proxy_ty_param::#fn_name #generic_types(*self, #args) }
726+
quote! { #proxy_ty_param::#fn_name #generic_types(*self, #args) #await_token }
725727
}
726728

727729
// `&self` or `&mut self` receiver
728730
SelfType::Ref | SelfType::Mut => {
729731
// The proxy type could be anything in the `Ref` case, and `&mut`
730732
// or Box in the `Mut` case.
731-
quote! { #proxy_ty_param::#fn_name #generic_types(self, #args) }
733+
quote! { #proxy_ty_param::#fn_name #generic_types(self, #args) #await_token }
732734
}
733735
};
734736

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[auto_impl::auto_impl(&, &mut, Arc, Box, Rc)]
2+
trait AsyncTrait {
3+
async fn foo(&self);
4+
}
5+
6+
fn main() {}

tests/ui.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ fn ui_compile_fail() {
1515

1616
#[rustversion::since(1.51)]
1717
#[test]
18-
fn ui_recent_compile_pass() {
18+
fn ui_since_1_51_compile_pass() {
1919
let t = TestCases::new();
20-
t.pass("tests/recent/compile-pass/*.rs");
20+
t.pass("tests/since_1.51/compile-pass/*.rs");
21+
}
22+
23+
#[rustversion::since(1.75)]
24+
#[test]
25+
fn ui_since_1_75_compile_pass() {
26+
let t = TestCases::new();
27+
t.pass("tests/since_1.75/compile-pass/*.rs");
2128
}

0 commit comments

Comments
 (0)