File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 1- use syn:: parse:: { Parse , ParseStream , Result } ;
1+ use proc_macro2:: Span ;
2+ use syn:: parse:: { Error , Parse , ParseStream , Result } ;
3+ use syn:: Token ;
24
5+ #[ derive( Copy , Clone ) ]
36pub struct Args {
4- pub local : bool
7+ pub local : bool ,
58}
69
710mod kw {
8- syn:: custom_keyword!( local ) ;
11+ syn:: custom_keyword!( Send ) ;
912}
1013
1114impl Parse for Args {
1215 fn parse ( input : ParseStream ) -> Result < Self > {
13- let local : Option < kw :: local > = input . parse ( ) ? ;
14- Ok ( Args {
15- local : local . is_some ( ) ,
16- } )
16+ match try_parse ( input ) {
17+ Ok ( args ) if input . is_empty ( ) => Ok ( args ) ,
18+ _ => Err ( error ( ) ) ,
19+ }
1720 }
1821}
22+
23+ fn try_parse ( input : ParseStream ) -> Result < Args > {
24+ if input. peek ( Token ! [ ?] ) {
25+ input. parse :: < Token ! [ ?] > ( ) ?;
26+ input. parse :: < kw:: Send > ( ) ?;
27+ Ok ( Args { local : true } )
28+ } else {
29+ Ok ( Args { local : false } )
30+ }
31+ }
32+
33+ fn error ( ) -> Error {
34+ let msg = "expected #[async_trait] or #[async_trait(?Send)]" ;
35+ Error :: new ( Span :: call_site ( ) , msg)
36+ }
Original file line number Diff line number Diff line change @@ -117,12 +117,12 @@ pub async fn test_object_safe_with_default() {
117117}
118118
119119pub async fn test_object_no_send ( ) {
120- #[ async_trait( local ) ]
120+ #[ async_trait( ? Send ) ]
121121 trait ObjectSafe : Sync {
122122 async fn f ( & self ) { }
123123 }
124124
125- #[ async_trait( local ) ]
125+ #[ async_trait( ? Send ) ]
126126 impl ObjectSafe for Struct {
127127 async fn f ( & self ) { }
128128 }
You can’t perform that action at this time.
0 commit comments