From 43a080d52baf84e24bbbfc283773efd40d1dc62c Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 29 Dec 2023 23:08:56 +0800 Subject: [PATCH] fix(napi): apply clippy suggestions (#1878) --- crates/napi/src/bindgen_runtime/module_register.rs | 5 ++++- crates/napi/src/env.rs | 2 +- examples/napi/src/lib.rs | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/module_register.rs b/crates/napi/src/bindgen_runtime/module_register.rs index 25f78a0f..d3bcffeb 100644 --- a/crates/napi/src/bindgen_runtime/module_register.rs +++ b/crates/napi/src/bindgen_runtime/module_register.rs @@ -396,7 +396,10 @@ pub unsafe extern "C" fn napi_register_module_v1( } let (ctor, props): (Vec<_>, Vec<_>) = props.iter().partition(|prop| prop.is_ctor); - let ctor = ctor.get(0).map(|c| c.raw().method.unwrap()).unwrap_or(noop); + let ctor = ctor + .first() + .map(|c| c.raw().method.unwrap()) + .unwrap_or(noop); let raw_props: Vec<_> = props.iter().map(|prop| prop.raw()).collect(); let js_class_name = CStr::from_bytes_with_nul_unchecked(js_name.as_bytes()); diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index 3e578be3..b5fb5820 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -1567,7 +1567,7 @@ pub(crate) unsafe extern "C" fn trampoline_setter< let closure: &F = Box::leak(unsafe { Box::from_raw(closure_data_ptr.cast()) }); let env = unsafe { Env::from_raw(raw_env) }; raw_args - .get(0) + .first() .ok_or_else(|| Error::new(Status::InvalidArg, "Missing argument in property setter")) .and_then(|value| unsafe { V::from_napi_value(raw_env, *value) }) .and_then(|value| { diff --git a/examples/napi/src/lib.rs b/examples/napi/src/lib.rs index ec552067..f2470a11 100644 --- a/examples/napi/src/lib.rs +++ b/examples/napi/src/lib.rs @@ -2,6 +2,7 @@ #![allow(unreachable_code)] #![allow(clippy::disallowed_names)] #![allow(clippy::uninlined_format_args)] +#![allow(clippy::new_without_default)] #[macro_use] extern crate napi_derive;