diff --git a/crates/napi/src/bindgen_runtime/js_values/bigint.rs b/crates/napi/src/bindgen_runtime/js_values/bigint.rs index 27100318..67256488 100644 --- a/crates/napi/src/bindgen_runtime/js_values/bigint.rs +++ b/crates/napi/src/bindgen_runtime/js_values/bigint.rs @@ -52,7 +52,7 @@ impl FromNapiValue for BigInt { ptr::null_mut(), ) })?; - let mut words: Vec = Vec::with_capacity(word_count as usize); + let mut words: Vec = Vec::with_capacity(word_count); let mut sign_bit = 0; unsafe { @@ -64,7 +64,7 @@ impl FromNapiValue for BigInt { words.as_mut_ptr(), ))?; - words.set_len(word_count as usize); + words.set_len(word_count); } if word_count == 0 { words = vec![0]; @@ -155,7 +155,7 @@ impl ToNapiValue for BigInt { impl ToNapiValue for i128 { unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> crate::Result { let mut raw_value = ptr::null_mut(); - let sign_bit = if val > 0 { 0 } else { 1 }; + let sign_bit = i32::from(val <= 0); let words = &val as *const i128 as *const u64; check_status!(unsafe { sys::napi_create_bigint_words(env, sign_bit, 2, words, &mut raw_value) 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 f12c9bee..4ee5627b 100644 --- a/crates/napi/src/bindgen_runtime/js_values/value_ref.rs +++ b/crates/napi/src/bindgen_runtime/js_values/value_ref.rs @@ -66,6 +66,7 @@ impl Drop for Reference { impl Reference { #[doc(hidden)] + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn add_ref(env: crate::sys::napi_env, t: *mut c_void, value: RefInformation) { REFERENCE_MAP.borrow_mut(|map| { if let Some((_, previous_ref, previous_rc)) = map.insert(t, value) { diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index 20849d77..f9a9e3ec 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -115,7 +115,7 @@ impl Env { #[cfg(feature = "napi6")] pub fn create_bigint_from_i128(&self, value: i128) -> Result { let mut raw_value = ptr::null_mut(); - let sign_bit = if value > 0 { 0 } else { 1 }; + let sign_bit = i32::from(value <= 0); let words = &value as *const i128 as *const u64; check_status!(unsafe { sys::napi_create_bigint_words(self.0, sign_bit, 2, words, &mut raw_value) diff --git a/crates/napi/src/js_values/bigint.rs b/crates/napi/src/js_values/bigint.rs index 245cddb1..2725c7be 100644 --- a/crates/napi/src/js_values/bigint.rs +++ b/crates/napi/src/js_values/bigint.rs @@ -204,7 +204,7 @@ impl TryFrom for u64 { impl JsBigInt { /// pub fn get_words(&mut self) -> Result<(bool, Vec)> { - let mut words: Vec = Vec::with_capacity(self.word_count as usize); + let mut words: Vec = Vec::with_capacity(self.word_count); let word_count = &mut self.word_count; let mut sign_bit = 0; check_status!(unsafe { @@ -218,7 +218,7 @@ impl JsBigInt { })?; unsafe { - words.set_len(self.word_count as usize); + words.set_len(self.word_count); }; Ok((sign_bit == 1, words)) diff --git a/crates/napi/src/js_values/string/mod.rs b/crates/napi/src/js_values/string/mod.rs index 0e5eeff8..313e46b1 100644 --- a/crates/napi/src/js_values/string/mod.rs +++ b/crates/napi/src/js_values/string/mod.rs @@ -35,7 +35,7 @@ impl JsString { check_status!(unsafe { sys::napi_get_value_string_utf8(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length) })?; - Ok(length as usize) + Ok(length) } pub fn utf16_len(&self) -> Result { @@ -43,7 +43,7 @@ impl JsString { check_status!(unsafe { sys::napi_get_value_string_utf16(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length) })?; - Ok(length as usize) + Ok(length) } pub fn latin1_len(&self) -> Result { @@ -51,7 +51,7 @@ impl JsString { check_status!(unsafe { sys::napi_get_value_string_latin1(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length) })?; - Ok(length as usize) + Ok(length) } pub fn into_utf8(self) -> Result { diff --git a/examples/napi-compat-mode/src/object.rs b/examples/napi-compat-mode/src/object.rs index a8f62ca6..bf5649d9 100644 --- a/examples/napi-compat-mode/src/object.rs +++ b/examples/napi-compat-mode/src/object.rs @@ -87,7 +87,7 @@ fn test_delete_named_property(ctx: CallContext) -> Result { fn test_get_property(ctx: CallContext) -> Result { let obj = ctx.get::(0)?; let key = ctx.get::(1)?; - obj.get_property(&key) + obj.get_property(key) } #[js_function(1)] diff --git a/examples/napi/src/either.rs b/examples/napi/src/either.rs index ab00955b..a316a603 100644 --- a/examples/napi/src/either.rs +++ b/examples/napi/src/either.rs @@ -22,13 +22,7 @@ fn either3(input: Either3) -> u32 { match input { Either3::A(s) => s.len() as u32, Either3::B(n) => n, - Either3::C(b) => { - if b { - 1 - } else { - 0 - } - } + Either3::C(b) => u32::from(b), } } @@ -42,13 +36,7 @@ fn either4(input: Either4) -> u32 { match input { Either4::A(s) => s.len() as u32, Either4::B(n) => n, - Either4::C(b) => { - if b { - 1 - } else { - 0 - } - } + Either4::C(b) => u32::from(b), Either4::D(f) => match f.v { Either::A(s) => s.len() as u32, Either::B(n) => n, diff --git a/examples/napi/src/typed_array.rs b/examples/napi/src/typed_array.rs index 9cc5ae14..2d7caaef 100644 --- a/examples/napi/src/typed_array.rs +++ b/examples/napi/src/typed_array.rs @@ -69,5 +69,5 @@ impl Task for AsyncBuffer { #[napi] fn async_reduce_buffer(buf: Buffer) -> Result> { - Ok(AsyncTask::new(AsyncBuffer { buf: buf.clone() })) + Ok(AsyncTask::new(AsyncBuffer { buf })) } diff --git a/memory-testing/src/lib.rs b/memory-testing/src/lib.rs index b41c1362..1b0c432d 100644 --- a/memory-testing/src/lib.rs +++ b/memory-testing/src/lib.rs @@ -75,7 +75,7 @@ pub fn test_async(env: Env) -> napi::Result { #[napi] pub fn from_js(env: Env, input_object: Object) -> napi::Result { - let a: Welcome = env.from_js_value(&input_object)?; + let a: Welcome = env.from_js_value(input_object)?; Ok(serde_json::to_string(&a)?) }