From f49b7fc6da7a6e76b40a12ffebddcd6de9987196 Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Tue, 6 Jul 2021 15:01:13 +0200 Subject: [PATCH] tokio-macros: compat with clippy::unwrap_used (#3926) --- tokio-macros/src/entry.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index ddc19585d7b..c5db13cc47b 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -201,12 +201,15 @@ fn parse_knobs( for arg in args { match arg { syn::NestedMeta::Meta(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() { + let ident = namevalue + .path + .get_ident() + .ok_or_else(|| { + syn::Error::new_spanned(&namevalue, "Must have specified ident") + })? + .to_string() + .to_lowercase(); + match ident.as_str() { "worker_threads" => { config.set_worker_threads( namevalue.lit.clone(), @@ -239,12 +242,11 @@ fn parse_knobs( } } syn::NestedMeta::Meta(syn::Meta::Path(path)) => { - let ident = path.get_ident(); - if ident.is_none() { - let msg = "Must have specified ident"; - return Err(syn::Error::new_spanned(path, msg)); - } - let name = ident.unwrap().to_string().to_lowercase(); + let name = path + .get_ident() + .ok_or_else(|| syn::Error::new_spanned(&path, "Must have specified ident"))? + .to_string() + .to_lowercase(); let msg = match name.as_str() { "threaded_scheduler" | "multi_thread" => { format!( @@ -326,11 +328,11 @@ fn parse_knobs( #rt .enable_all() .build() - .unwrap() + .expect("Failed building the Runtime") .block_on(async #body) } }) - .unwrap(); + .expect("Parsing failure"); input.block.brace_token = brace_token; let result = quote! {