style: clippy fix (#1711)

This commit is contained in:
LongYinan 2023-08-30 16:41:13 +08:00 committed by GitHub
parent fda46658f4
commit 05b4be4d80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 11 additions and 10 deletions

View file

@ -918,8 +918,8 @@ impl NapiImpl {
} }
fn rm_raw_prefix(s: &str) -> &str { fn rm_raw_prefix(s: &str) -> &str {
if s.starts_with("r#") { if let Some(stripped) = s.strip_prefix("r#") {
&s[2..] stripped
} else { } else {
s s
} }

View file

@ -79,7 +79,7 @@ impl ToTypeDef for NapiFn {
.ts_generic_types .ts_generic_types
.as_ref() .as_ref()
.map(|g| format!("<{}>", g)) .map(|g| format!("<{}>", g))
.unwrap_or_else(|| "".to_string()), .unwrap_or_default(),
args = self args = self
.ts_args_type .ts_args_type
.clone() .clone()

View file

@ -210,7 +210,7 @@ pub unsafe extern "C" fn symbol_generator<T: Generator>(
"Create generator state failed" "Create generator state failed"
); );
let properties = vec![sys::napi_property_descriptor { let properties = [sys::napi_property_descriptor {
utf8name: GENERATOR_STATE_KEY.as_ptr().cast(), utf8name: GENERATOR_STATE_KEY.as_ptr().cast(),
name: ptr::null_mut(), name: ptr::null_mut(),
method: None, method: None,

View file

@ -402,7 +402,6 @@ unsafe extern "C" fn finalizer<Data, T: Finalizer<RustType = Data>>(
} }
DataManagedType::Owned => { DataManagedType::Owned => {
if data.ref_count() == 1 { if data.ref_count() == 1 {
let length = length;
unsafe { Vec::from_raw_parts(finalize_data as *mut Data, length, length) }; unsafe { Vec::from_raw_parts(finalize_data as *mut Data, length, length) };
} }
} }

View file

@ -150,6 +150,6 @@ impl FromNapiValue for DateTime<Utc> {
(milliseconds_since_epoch_utc % 1_000 * 1_000_000) as u32, (milliseconds_since_epoch_utc % 1_000 * 1_000_000) as u32,
) )
.ok_or_else(|| Error::new(Status::DateExpected, "Found invalid date".to_owned()))?; .ok_or_else(|| Error::new(Status::DateExpected, "Found invalid date".to_owned()))?;
Ok(DateTime::<Utc>::from_utc(naive, Utc)) Ok(DateTime::<Utc>::from_naive_utc_and_offset(naive, Utc))
} }
} }

View file

@ -138,7 +138,7 @@ impl<T: 'static> Reference<T> {
let s_ptr = Box::into_raw(Box::new(s)); let s_ptr = Box::into_raw(Box::new(s));
let prev_drop_fn = unsafe { Box::from_raw(self.finalize_callbacks.get()) }; let prev_drop_fn = unsafe { Box::from_raw(self.finalize_callbacks.get()) };
let drop_fn = Box::new(move || { let drop_fn = Box::new(move || {
unsafe { Box::from_raw(s_ptr) }; drop(unsafe { Box::from_raw(s_ptr) });
prev_drop_fn(); prev_drop_fn();
}); });
self.finalize_callbacks.set(Box::into_raw(drop_fn)); self.finalize_callbacks.set(Box::into_raw(drop_fn));

View file

@ -242,7 +242,7 @@ pub fn register_class(
let val = inner.entry(rust_name).or_default(); let val = inner.entry(rust_name).or_default();
let val = val.entry(js_mod).or_default(); let val = val.entry(js_mod).or_default();
val.0 = js_name; val.0 = js_name;
val.1.extend(props.into_iter()); val.1.extend(props);
}); });
} }

View file

@ -740,6 +740,7 @@ impl Env {
Ok(unsafe { JsFunction::from_raw_unchecked(self.0, raw_result) }) Ok(unsafe { JsFunction::from_raw_unchecked(self.0, raw_result) })
} }
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn wrap<T: 'static>(&self, js_object: &mut JsObject, native_object: T) -> Result<()> { pub fn wrap<T: 'static>(&self, js_object: &mut JsObject, native_object: T) -> Result<()> {
check_status!(unsafe { check_status!(unsafe {
sys::napi_wrap( sys::napi_wrap(
@ -813,7 +814,7 @@ impl Env {
} }
} }
pub fn drop_wrapped<T: 'static>(&self, js_object: &mut JsObject) -> Result<()> { pub fn drop_wrapped<T: 'static>(&self, js_object: &JsObject) -> Result<()> {
unsafe { unsafe {
let mut unknown_tagged_object = ptr::null_mut(); let mut unknown_tagged_object = ptr::null_mut();
check_status!(sys::napi_remove_wrap( check_status!(sys::napi_remove_wrap(

View file

@ -136,6 +136,7 @@ impl ThreadsafeFunctionHandle {
f(aborted_guard) f(aborted_guard)
} }
#[allow(clippy::arc_with_non_send_sync)]
fn null() -> Arc<Self> { fn null() -> Arc<Self> {
Self::new(null_mut()) Self::new(null_mut())
} }

View file

@ -50,7 +50,7 @@ fn add_native_count(ctx: CallContext) -> Result<JsNumber> {
#[js_function] #[js_function]
fn renew_wrapped(ctx: CallContext) -> Result<JsUndefined> { fn renew_wrapped(ctx: CallContext) -> Result<JsUndefined> {
let mut this: JsObject = ctx.this_unchecked(); let mut this: JsObject = ctx.this_unchecked();
ctx.env.drop_wrapped::<NativeClass>(&mut this)?; ctx.env.drop_wrapped::<NativeClass>(&this)?;
ctx.env.wrap(&mut this, NativeClass { value: 42 })?; ctx.env.wrap(&mut this, NativeClass { value: 42 })?;
ctx.env.get_undefined() ctx.env.get_undefined()
} }