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 ;
2
4
5
+ #[ derive( Copy , Clone ) ]
3
6
pub struct Args {
4
- pub local : bool
7
+ pub local : bool ,
5
8
}
6
9
7
10
mod kw {
8
- syn:: custom_keyword!( local ) ;
11
+ syn:: custom_keyword!( Send ) ;
9
12
}
10
13
11
14
impl Parse for Args {
12
15
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
+ }
17
20
}
18
21
}
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() {
117
117
}
118
118
119
119
pub async fn test_object_no_send ( ) {
120
- #[ async_trait( local ) ]
120
+ #[ async_trait( ? Send ) ]
121
121
trait ObjectSafe : Sync {
122
122
async fn f ( & self ) { }
123
123
}
124
124
125
- #[ async_trait( local ) ]
125
+ #[ async_trait( ? Send ) ]
126
126
impl ObjectSafe for Struct {
127
127
async fn f ( & self ) { }
128
128
}
You can’t perform that action at this time.
0 commit comments