File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ use std::future::Future;
10
10
11
11
use trait_variant:: make_variant;
12
12
13
- #[ make_variant( SendIntFactory : Send ) ]
14
- trait IntFactory {
13
+ #[ make_variant( IntFactory : Send ) ]
14
+ pub trait LocalIntFactory {
15
15
const NAME : & ' static str ;
16
16
17
17
type MyFut < ' a > : Future
@@ -24,4 +24,11 @@ trait IntFactory {
24
24
fn another_async ( & self , input : Result < ( ) , & str > ) -> Self :: MyFut < ' _ > ;
25
25
}
26
26
27
+ #[ allow( dead_code) ]
28
+ fn spawn_task ( factory : impl IntFactory + ' static ) {
29
+ tokio:: spawn ( async move {
30
+ let _int = factory. make ( 1 , "foo" ) . await ;
31
+ } ) ;
32
+ }
33
+
27
34
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -56,15 +56,29 @@ pub fn make_variant(
56
56
let attrs = parse_macro_input ! ( attr as Attrs ) ;
57
57
let item = parse_macro_input ! ( item as ItemTrait ) ;
58
58
59
+ let maybe_allow_async_lint = if attrs
60
+ . variant
61
+ . bounds
62
+ . iter ( )
63
+ . any ( |b| b. path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) == "Send" )
64
+ {
65
+ quote ! { #[ allow( async_fn_in_trait) ] }
66
+ } else {
67
+ quote ! { }
68
+ } ;
69
+
59
70
let variant = mk_variant ( & attrs, & item) ;
60
71
let blanket_impl = mk_blanket_impl ( & attrs, & item) ;
61
- let output = quote ! {
72
+
73
+ quote ! {
74
+ #maybe_allow_async_lint
62
75
#item
76
+
63
77
#variant
64
- #blanket_impl
65
- } ;
66
78
67
- output. into ( )
79
+ #blanket_impl
80
+ }
81
+ . into ( )
68
82
}
69
83
70
84
fn mk_variant ( attrs : & Attrs , tr : & ItemTrait ) -> TokenStream {
You can’t perform that action at this time.
0 commit comments