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;
1010
1111use trait_variant:: make_variant;
1212
13- #[ make_variant( SendIntFactory : Send ) ]
14- trait IntFactory {
13+ #[ make_variant( IntFactory : Send ) ]
14+ pub trait LocalIntFactory {
1515 const NAME : & ' static str ;
1616
1717 type MyFut < ' a > : Future
@@ -24,4 +24,11 @@ trait IntFactory {
2424 fn another_async ( & self , input : Result < ( ) , & str > ) -> Self :: MyFut < ' _ > ;
2525}
2626
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+
2734fn main ( ) { }
Original file line number Diff line number Diff line change @@ -56,15 +56,29 @@ pub fn make_variant(
5656 let attrs = parse_macro_input ! ( attr as Attrs ) ;
5757 let item = parse_macro_input ! ( item as ItemTrait ) ;
5858
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+
5970 let variant = mk_variant ( & attrs, & item) ;
6071 let blanket_impl = mk_blanket_impl ( & attrs, & item) ;
61- let output = quote ! {
72+
73+ quote ! {
74+ #maybe_allow_async_lint
6275 #item
76+
6377 #variant
64- #blanket_impl
65- } ;
6678
67- output. into ( )
79+ #blanket_impl
80+ }
81+ . into ( )
6882}
6983
7084fn mk_variant ( attrs : & Attrs , tr : & ItemTrait ) -> TokenStream {
You can’t perform that action at this time.
0 commit comments