From 132a9a4ae2a8c4c474c912aa3f8f32a354e27cfc Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 28 Feb 2022 12:09:40 +0800 Subject: [PATCH] chore: fix `clippy::needless_late_init` lint --- crates/macro/src/lib.rs | 12 ++++---- crates/napi/src/threadsafe_function.rs | 38 ++++++++++++-------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 21b8241b..118e02f7 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -326,12 +326,12 @@ fn replace_napi_attr_in_mod( #[napi(namespace = #js_namespace)] ) }; - let struct_opts: BindgenAttrs; - if let Some(TokenTree::Group(g)) = new_attr.tokens.into_iter().next() { - struct_opts = syn::parse2(g.stream()).ok()?; - } else { - struct_opts = syn::parse2(quote! {}).ok()?; - } + let struct_opts: BindgenAttrs = + if let Some(TokenTree::Group(g)) = new_attr.tokens.into_iter().next() { + syn::parse2(g.stream()).ok()? + } else { + syn::parse2(quote! {}).ok()? + }; attrs.remove(index); Some(struct_opts) } else { diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 7f87d2fc..4a0848c5 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -373,12 +373,10 @@ unsafe extern "C" fn call_js_cb( }) }); - let status; - // Follow async callback conventions: https://nodejs.org/en/knowledge/errors/what-are-the-error-conventions/ // Check if the Result is okay, if so, pass a null as the first (error) argument automatically. // If the Result is an error, pass that as the first argument. - match ret { + let status = match ret { Ok(values) => { let values = values.iter().map(|v| unsafe { v.raw() }); let args: Vec = if ES::VALUE == ErrorStrategy::CalleeHandled::VALUE { @@ -388,7 +386,7 @@ unsafe extern "C" fn call_js_cb( } else { values.collect() }; - status = unsafe { + unsafe { sys::napi_call_function( raw_env, recv, @@ -397,24 +395,22 @@ unsafe extern "C" fn call_js_cb( args.as_ptr(), ptr::null_mut(), ) - }; + } } - Err(e) if ES::VALUE == ErrorStrategy::Fatal::VALUE => { - status = unsafe { sys::napi_fatal_exception(raw_env, JsError::from(e).into_value(raw_env)) }; - } - Err(e) => { - status = unsafe { - sys::napi_call_function( - raw_env, - recv, - js_callback, - 1, - [JsError::from(e).into_value(raw_env)].as_mut_ptr(), - ptr::null_mut(), - ) - }; - } - } + Err(e) if ES::VALUE == ErrorStrategy::Fatal::VALUE => unsafe { + sys::napi_fatal_exception(raw_env, JsError::from(e).into_value(raw_env)) + }, + Err(e) => unsafe { + sys::napi_call_function( + raw_env, + recv, + js_callback, + 1, + [JsError::from(e).into_value(raw_env)].as_mut_ptr(), + ptr::null_mut(), + ) + }, + }; if status == sys::Status::napi_ok { return; }