Skip to content

Commit

Permalink
macros: fix handling of arguments of #[tokio::main] attribute (tokio-…
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Sep 22, 2019
1 parent 376d638 commit ddbb0c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tokio-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ proc-macro = true

[dependencies]
quote = "1"
syn = { version = "1", features = ["full"] }
syn = { version = "1.0.3", features = ["full"] }

[dev-dependencies]
tokio = { version = "=0.2.0-alpha.5", path = "../tokio", default-features = false, features = ["rt-full"] }
Expand Down
14 changes: 8 additions & 6 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
let mut runtime = RuntimeType::Multi;

for arg in args {
if let syn::NestedMeta::Meta(syn::Meta::Path(ident)) = arg {
let seg = ident.segments.first().expect("Must have specified ident");
match seg.ident.to_string().to_lowercase().as_str() {
if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = arg {
let ident = path.get_ident();
if ident.is_none() {
let msg = "Must have specified ident";
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
match ident.unwrap().to_string().to_lowercase().as_str() {
"multi_thread" => runtime = RuntimeType::Multi,
"single_thread" => runtime = RuntimeType::Single,
name => {
let msg = format!("Unknown attribute {} is specified", name);
return syn::Error::new_spanned(ident, msg)
.to_compile_error()
.into();
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
}
}
Expand Down

0 comments on commit ddbb0c3

Please sign in to comment.