chore: fix clippy::needless_late_init lint

This commit is contained in:
messense 2022-02-28 12:09:40 +08:00
parent ab3ea5a58a
commit 132a9a4ae2
2 changed files with 23 additions and 27 deletions

View file

@ -326,12 +326,12 @@ fn replace_napi_attr_in_mod(
#[napi(namespace = #js_namespace)]
)
};
let struct_opts: BindgenAttrs;
let struct_opts: BindgenAttrs =
if let Some(TokenTree::Group(g)) = new_attr.tokens.into_iter().next() {
struct_opts = syn::parse2(g.stream()).ok()?;
syn::parse2(g.stream()).ok()?
} else {
struct_opts = syn::parse2(quote! {}).ok()?;
}
syn::parse2(quote! {}).ok()?
};
attrs.remove(index);
Some(struct_opts)
} else {

View file

@ -373,12 +373,10 @@ unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
})
});
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<sys::napi_value> = if ES::VALUE == ErrorStrategy::CalleeHandled::VALUE {
@ -388,7 +386,7 @@ unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
} else {
values.collect()
};
status = unsafe {
unsafe {
sys::napi_call_function(
raw_env,
recv,
@ -397,13 +395,12 @@ unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
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 {
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,
@ -412,9 +409,8 @@ unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
[JsError::from(e).into_value(raw_env)].as_mut_ptr(),
ptr::null_mut(),
)
},
};
}
}
if status == sys::Status::napi_ok {
return;
}