Skip to content

Commit bbceb93

Browse files
authored
Merge pull request #14 from dtolnay/local
Rename local to ?Send
2 parents 79ed679 + 24b264c commit bbceb93

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/args.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
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)]
36
pub struct Args {
4-
pub local: bool
7+
pub local: bool,
58
}
69

710
mod kw {
8-
syn::custom_keyword!(local);
11+
syn::custom_keyword!(Send);
912
}
1013

1114
impl 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+
}

tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ pub async fn test_object_safe_with_default() {
117117
}
118118

119119
pub 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
}

0 commit comments

Comments
 (0)