diff --git a/crates/backend/src/codegen/struct.rs b/crates/backend/src/codegen/struct.rs index ae0498f5..3a105acc 100644 --- a/crates/backend/src/codegen/struct.rs +++ b/crates/backend/src/codegen/struct.rs @@ -918,8 +918,8 @@ impl NapiImpl { } fn rm_raw_prefix(s: &str) -> &str { - if s.starts_with("r#") { - &s[2..] + if let Some(stripped) = s.strip_prefix("r#") { + stripped } else { s } diff --git a/crates/backend/src/typegen/fn.rs b/crates/backend/src/typegen/fn.rs index 8832650c..1d261c0c 100644 --- a/crates/backend/src/typegen/fn.rs +++ b/crates/backend/src/typegen/fn.rs @@ -79,7 +79,7 @@ impl ToTypeDef for NapiFn { .ts_generic_types .as_ref() .map(|g| format!("<{}>", g)) - .unwrap_or_else(|| "".to_string()), + .unwrap_or_default(), args = self .ts_args_type .clone() diff --git a/crates/napi/src/bindgen_runtime/iterator.rs b/crates/napi/src/bindgen_runtime/iterator.rs index 5ed75b22..a0a7a92a 100644 --- a/crates/napi/src/bindgen_runtime/iterator.rs +++ b/crates/napi/src/bindgen_runtime/iterator.rs @@ -210,7 +210,7 @@ pub unsafe extern "C" fn symbol_generator( "Create generator state failed" ); - let properties = vec![sys::napi_property_descriptor { + let properties = [sys::napi_property_descriptor { utf8name: GENERATOR_STATE_KEY.as_ptr().cast(), name: ptr::null_mut(), method: None, diff --git a/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs b/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs index db7804fc..00acafbb 100644 --- a/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs +++ b/crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs @@ -402,7 +402,6 @@ unsafe extern "C" fn finalizer>( } DataManagedType::Owned => { if data.ref_count() == 1 { - let length = length; unsafe { Vec::from_raw_parts(finalize_data as *mut Data, length, length) }; } } diff --git a/crates/napi/src/bindgen_runtime/js_values/date.rs b/crates/napi/src/bindgen_runtime/js_values/date.rs index 6ed32266..689432fc 100644 --- a/crates/napi/src/bindgen_runtime/js_values/date.rs +++ b/crates/napi/src/bindgen_runtime/js_values/date.rs @@ -150,6 +150,6 @@ impl FromNapiValue for DateTime { (milliseconds_since_epoch_utc % 1_000 * 1_000_000) as u32, ) .ok_or_else(|| Error::new(Status::DateExpected, "Found invalid date".to_owned()))?; - Ok(DateTime::::from_utc(naive, Utc)) + Ok(DateTime::::from_naive_utc_and_offset(naive, Utc)) } } diff --git a/crates/napi/src/bindgen_runtime/js_values/value_ref.rs b/crates/napi/src/bindgen_runtime/js_values/value_ref.rs index ba937d17..ed6f18f6 100644 --- a/crates/napi/src/bindgen_runtime/js_values/value_ref.rs +++ b/crates/napi/src/bindgen_runtime/js_values/value_ref.rs @@ -138,7 +138,7 @@ impl Reference { let s_ptr = Box::into_raw(Box::new(s)); let prev_drop_fn = unsafe { Box::from_raw(self.finalize_callbacks.get()) }; let drop_fn = Box::new(move || { - unsafe { Box::from_raw(s_ptr) }; + drop(unsafe { Box::from_raw(s_ptr) }); prev_drop_fn(); }); self.finalize_callbacks.set(Box::into_raw(drop_fn)); diff --git a/crates/napi/src/bindgen_runtime/module_register.rs b/crates/napi/src/bindgen_runtime/module_register.rs index 1c45d66d..a5bbba31 100644 --- a/crates/napi/src/bindgen_runtime/module_register.rs +++ b/crates/napi/src/bindgen_runtime/module_register.rs @@ -242,7 +242,7 @@ pub fn register_class( let val = inner.entry(rust_name).or_default(); let val = val.entry(js_mod).or_default(); val.0 = js_name; - val.1.extend(props.into_iter()); + val.1.extend(props); }); } diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index cc8996da..37d92157 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -740,6 +740,7 @@ impl Env { Ok(unsafe { JsFunction::from_raw_unchecked(self.0, raw_result) }) } + #[allow(clippy::needless_pass_by_ref_mut)] pub fn wrap(&self, js_object: &mut JsObject, native_object: T) -> Result<()> { check_status!(unsafe { sys::napi_wrap( @@ -813,7 +814,7 @@ impl Env { } } - pub fn drop_wrapped(&self, js_object: &mut JsObject) -> Result<()> { + pub fn drop_wrapped(&self, js_object: &JsObject) -> Result<()> { unsafe { let mut unknown_tagged_object = ptr::null_mut(); check_status!(sys::napi_remove_wrap( diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 65deefe2..46913425 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -136,6 +136,7 @@ impl ThreadsafeFunctionHandle { f(aborted_guard) } + #[allow(clippy::arc_with_non_send_sync)] fn null() -> Arc { Self::new(null_mut()) } diff --git a/examples/napi-compat-mode/src/class.rs b/examples/napi-compat-mode/src/class.rs index 7a735a26..7a2460b5 100644 --- a/examples/napi-compat-mode/src/class.rs +++ b/examples/napi-compat-mode/src/class.rs @@ -50,7 +50,7 @@ fn add_native_count(ctx: CallContext) -> Result { #[js_function] fn renew_wrapped(ctx: CallContext) -> Result { let mut this: JsObject = ctx.this_unchecked(); - ctx.env.drop_wrapped::(&mut this)?; + ctx.env.drop_wrapped::(&this)?; ctx.env.wrap(&mut this, NativeClass { value: 42 })?; ctx.env.get_undefined() }