Skip to content

Commit

Permalink
Update syn requirement from 1 to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
lakako committed Oct 23, 2024
1 parent 284bd36 commit ce97964
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyo3-asyncio-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1"
syn = { version = "1", features = ["full"] }
syn = { version = "2", features = ["full"] }
27 changes: 21 additions & 6 deletions pyo3-asyncio-macros/src/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::E

fn parse_knobs(
input: syn::ItemFn,
args: syn::AttributeArgs,
args: Vec<syn::Meta>,
is_test: bool,
rt_multi_thread: bool,
) -> Result<TokenStream, syn::Error> {
Expand All @@ -156,18 +156,32 @@ fn parse_knobs(

for arg in args {
match arg {
syn::NestedMeta::Meta(syn::Meta::NameValue(namevalue)) => {
syn::Meta::NameValue(namevalue) => {
let ident = namevalue.path.get_ident();
if ident.is_none() {
let msg = "Must have specified ident";
return Err(syn::Error::new_spanned(namevalue, msg));
}
match ident.unwrap().to_string().to_lowercase().as_str() {
"worker_threads" => {
config.set_worker_threads(namevalue.lit.clone(), namevalue.span())?;
if let syn::Expr::Lit(expr_lit) = &namevalue.value {
config.set_worker_threads(expr_lit.lit.clone(), namevalue.span())?;
} else {
return Err(syn::Error::new_spanned(
&namevalue.value,
"Expected a literal value",
));
}
}
"flavor" => {
config.set_flavor(namevalue.lit.clone(), namevalue.span())?;
if let syn::Expr::Lit(expr_lit) = &namevalue.value {
config.set_flavor(expr_lit.lit.clone(), namevalue.span())?;
} else {
return Err(syn::Error::new_spanned(
&namevalue.value,
"Expected a literal value",
));
}
}
"core_threads" => {
let msg = "Attribute `core_threads` is renamed to `worker_threads`";
Expand All @@ -179,7 +193,7 @@ fn parse_knobs(
}
}
}
syn::NestedMeta::Meta(syn::Meta::Path(path)) => {
syn::Meta::Path(path) => {
let ident = path.get_ident();
if ident.is_none() {
let msg = "Must have specified ident";
Expand Down Expand Up @@ -279,7 +293,8 @@ fn parse_knobs(
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub(crate) fn main(args: TokenStream, item: TokenStream, rt_multi_thread: bool) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
let args = syn::parse_macro_input!(args with syn::punctuated::Punctuated::<syn::Meta, syn::Token![,]>::parse_terminated);
let args: Vec<syn::Meta> = args.into_iter().collect();

if input.sig.ident == "main" && !input.sig.inputs.is_empty() {
let msg = "the main function cannot accept arguments";
Expand Down

0 comments on commit ce97964

Please sign in to comment.