Skip to content

Commit

Permalink
Remove let () =
Browse files Browse the repository at this point in the history
  • Loading branch information
akonradi-signal committed Oct 23, 2024
1 parent cabacd8 commit ad2cb8f
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 89 deletions.
4 changes: 2 additions & 2 deletions crates/neon/src/sys/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
};

pub unsafe fn new(out: &mut Local, env: Env, length: usize) {
let () = napi::create_array_with_length(env, length, out as *mut _).unwrap();
napi::create_array_with_length(env, length, out as *mut _).unwrap();
}

/// Gets the length of a `napi_value` containing a JavaScript Array.
Expand All @@ -16,6 +16,6 @@ pub unsafe fn new(out: &mut Local, env: Env, length: usize) {
/// exception.
pub unsafe fn len(env: Env, array: Local) -> u32 {
let mut len = 0;
let () = napi::get_array_length(env, array, &mut len as *mut _).unwrap();
napi::get_array_length(env, array, &mut len as *mut _).unwrap();
len
}
8 changes: 4 additions & 4 deletions crates/neon/src/sys/arraybuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub unsafe fn new(env: Env, len: usize) -> Result<Local, napi::Status> {
let mut buf = MaybeUninit::uninit();
let status = napi::create_arraybuffer(env, len, null_mut(), buf.as_mut_ptr());

let () = match status {
match status {
Err(err @ napi::Status::PendingException) => return Err(err),
status => status.unwrap(),
};
Expand All @@ -30,7 +30,7 @@ where
let length = buf.len();
let mut result = MaybeUninit::uninit();

let () = napi::create_external_arraybuffer(
napi::create_external_arraybuffer(
env,
buf.as_mut_ptr() as *mut _,
length,
Expand All @@ -55,7 +55,7 @@ pub unsafe fn as_mut_slice<'a>(env: Env, buf: Local) -> &'a mut [u8] {
let mut data = MaybeUninit::uninit();
let mut size = 0usize;

let () = napi::get_arraybuffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();
napi::get_arraybuffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();

if size == 0 {
return &mut [];
Expand All @@ -70,7 +70,7 @@ pub unsafe fn size(env: Env, buf: Local) -> usize {
let mut data = MaybeUninit::uninit();
let mut size = 0usize;

let () = napi::get_arraybuffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();
napi::get_arraybuffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();

size
}
2 changes: 1 addition & 1 deletion crates/neon/src/sys/async_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub unsafe fn schedule<I, O, D>(
let work = &mut data.work as *mut _;

// Create the `async_work`
let () = napi::create_async_work(
napi::create_async_work(
env,
ptr::null_mut(),
super::string(env, "neon_async_work"),
Expand Down
6 changes: 3 additions & 3 deletions crates/neon/src/sys/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub unsafe fn uninitialized(env: Env, len: usize) -> Result<(Local, *mut u8), na
let mut bytes = MaybeUninit::uninit();
let status = napi::create_buffer(env, len, bytes.as_mut_ptr(), buf.as_mut_ptr());

let () = match status {
match status {
Err(err @ napi::Status::PendingException) => return Err(err),
status => status.unwrap(),
};
Expand Down Expand Up @@ -64,7 +64,7 @@ pub unsafe fn as_mut_slice<'a>(env: Env, buf: Local) -> &'a mut [u8] {
let mut data = MaybeUninit::uninit();
let mut size = 0usize;

let () = napi::get_buffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();
napi::get_buffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();

if size == 0 {
return &mut [];
Expand All @@ -79,7 +79,7 @@ pub unsafe fn size(env: Env, buf: Local) -> usize {
let mut data = MaybeUninit::uninit();
let mut size = 0usize;

let () = napi::get_buffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();
napi::get_buffer_info(env, buf, data.as_mut_ptr(), &mut size as *mut _).unwrap();

size
}
11 changes: 5 additions & 6 deletions crates/neon/src/sys/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Arguments {
pub unsafe fn is_construct(env: Env, info: FunctionCallbackInfo) -> bool {
let mut target: MaybeUninit<Local> = MaybeUninit::zeroed();

let () = napi::get_new_target(env, info, target.as_mut_ptr()).unwrap();
napi::get_new_target(env, info, target.as_mut_ptr()).unwrap();

// get_new_target is guaranteed to assign to target, so it's initialized.
let target: Local = target.assume_init();
Expand All @@ -45,15 +45,14 @@ pub unsafe fn is_construct(env: Env, info: FunctionCallbackInfo) -> bool {
}

pub unsafe fn this(env: Env, info: FunctionCallbackInfo, out: &mut Local) {
let () =
napi::get_cb_info(env, info, null_mut(), null_mut(), out as *mut _, null_mut()).unwrap();
napi::get_cb_info(env, info, null_mut(), null_mut(), out as *mut _, null_mut()).unwrap();
}

/// Gets the number of arguments passed to the function.
// TODO: Remove this when `FunctionContext` is refactored to get call info upfront.
pub unsafe fn len(env: Env, info: FunctionCallbackInfo) -> usize {
let mut argc = 0usize;
let () = napi::get_cb_info(
napi::get_cb_info(
env,
info,
&mut argc as *mut _,
Expand All @@ -73,7 +72,7 @@ pub unsafe fn argv(env: Env, info: FunctionCallbackInfo) -> Arguments {
// Starts as the size allocated; after `get_cb_info` it is the number of arguments
let mut argc = ARGV_SIZE;

let () = napi::get_cb_info(
napi::get_cb_info(
env,
info,
&mut argc as *mut _,
Expand All @@ -88,7 +87,7 @@ pub unsafe fn argv(env: Env, info: FunctionCallbackInfo) -> Arguments {
// We know exactly how much space to reserve
let mut argv = Vec::with_capacity(argc);

let () = napi::get_cb_info(
napi::get_cb_info(
env,
info,
&mut argc as *mut _,
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/sys/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
/// `env` is a raw pointer. Please ensure it points to a napi_env that is valid for the current context.
pub unsafe fn new_date(env: Env, value: f64) -> Local {
let mut local = MaybeUninit::zeroed();
let () = napi::create_date(env, value, local.as_mut_ptr()).unwrap();
napi::create_date(env, value, local.as_mut_ptr()).unwrap();
local.assume_init()
}

Expand All @@ -24,6 +24,6 @@ pub unsafe fn new_date(env: Env, value: f64) -> Local {
/// `Local` must be an NAPI value associated with the given `Env`
pub unsafe fn value(env: Env, p: Local) -> f64 {
let mut value = 0.0;
let () = napi::get_date_value(env, p, &mut value as *mut _).unwrap();
napi::get_date_value(env, p, &mut value as *mut _).unwrap();
value
}
22 changes: 11 additions & 11 deletions crates/neon/src/sys/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
pub unsafe fn is_throwing(env: Env) -> bool {
let mut b: MaybeUninit<bool> = MaybeUninit::zeroed();

let () = napi::is_exception_pending(env, b.as_mut_ptr()).unwrap();
napi::is_exception_pending(env, b.as_mut_ptr()).unwrap();

b.assume_init()
}
Expand All @@ -18,55 +18,55 @@ pub unsafe fn catch_error(env: Env, error: *mut Local) -> bool {
return false;
}

let () = napi::get_and_clear_last_exception(env, error).unwrap();
napi::get_and_clear_last_exception(env, error).unwrap();

true
}

pub unsafe fn clear_exception(env: Env) {
let mut result = MaybeUninit::uninit();
let () = napi::is_exception_pending(env, result.as_mut_ptr()).unwrap();
napi::is_exception_pending(env, result.as_mut_ptr()).unwrap();

if !result.assume_init() {
return;
}

let mut result = MaybeUninit::uninit();
let () = napi::get_and_clear_last_exception(env, result.as_mut_ptr()).unwrap();
napi::get_and_clear_last_exception(env, result.as_mut_ptr()).unwrap();
}

pub unsafe fn throw(env: Env, val: Local) {
let () = napi::throw(env, val).unwrap();
napi::throw(env, val).unwrap();
}

pub unsafe fn new_error(env: Env, out: &mut Local, msg: Local) {
let mut result = MaybeUninit::uninit();
let () = napi::create_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();
napi::create_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();

*out = result.assume_init();
}

pub unsafe fn new_type_error(env: Env, out: &mut Local, msg: Local) {
let mut result = MaybeUninit::uninit();
let () = napi::create_type_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();
napi::create_type_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();

*out = result.assume_init();
}

pub unsafe fn new_range_error(env: Env, out: &mut Local, msg: Local) {
let mut result = MaybeUninit::uninit();
let () = napi::create_range_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();
napi::create_range_error(env, ptr::null_mut(), msg, result.as_mut_ptr()).unwrap();

*out = result.assume_init();
}

pub unsafe fn throw_error_from_utf8(env: Env, msg: *const u8, len: i32) {
let mut out = MaybeUninit::uninit();
let () =
napi::create_string_utf8(env, msg as *const _, len as usize, out.as_mut_ptr()).unwrap();

napi::create_string_utf8(env, msg as *const _, len as usize, out.as_mut_ptr()).unwrap();

let mut err = MaybeUninit::uninit();
let () = napi::create_error(env, ptr::null_mut(), out.assume_init(), err.as_mut_ptr()).unwrap();
napi::create_error(env, ptr::null_mut(), out.assume_init(), err.as_mut_ptr()).unwrap();

throw(env, err.assume_init());
}
Expand Down
6 changes: 3 additions & 3 deletions crates/neon/src/sys/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" fn finalize_external<T: 'static>(
/// <https://github.com/neon-bindings/neon/issues/591>
pub unsafe fn deref<T: 'static>(env: Env, local: Local) -> Option<*const T> {
let mut result = MaybeUninit::uninit();
let () = napi::typeof_value(env, local, result.as_mut_ptr()).unwrap();
napi::typeof_value(env, local, result.as_mut_ptr()).unwrap();

let result = result.assume_init();

Expand All @@ -48,7 +48,7 @@ pub unsafe fn deref<T: 'static>(env: Env, local: Local) -> Option<*const T> {
}

let mut result = MaybeUninit::uninit();
let () = napi::get_value_external(env, local, result.as_mut_ptr()).unwrap();
napi::get_value_external(env, local, result.as_mut_ptr()).unwrap();

let v = result.assume_init();
let v = &**v.cast_const().cast::<DebugSendWrapper<T>>() as *const T;
Expand All @@ -73,7 +73,7 @@ pub unsafe fn create<T: 'static>(env: Env, v: T, finalizer: fn(Env, T)) -> Local

// `napi_create_external` will only fail if the VM is in a throwing state
// or shutting down.
let () = status.unwrap();
status.unwrap();

let external = result.assume_init();

Expand Down
6 changes: 3 additions & 3 deletions crates/neon/src/sys/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
out.as_mut_ptr(),
);

let () = match status {
match status {
Err(err @ napi::Status::PendingException) => {
drop(Box::from_raw(data));

Expand Down Expand Up @@ -55,7 +55,7 @@ where
// If adding the finalizer fails the closure will leak, but it would
// be unsafe to drop it because there's no guarantee V8 won't use the
// pointer.
let () = status.unwrap();
status.unwrap();
}

Ok(out)
Expand All @@ -68,7 +68,7 @@ where
F: Fn(Env, napi::CallbackInfo) -> Local + 'static,
{
let mut data = MaybeUninit::uninit();
let () = napi::get_cb_info(
napi::get_cb_info(
env,
info,
ptr::null_mut(),
Expand Down
5 changes: 2 additions & 3 deletions crates/neon/src/sys/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use super::{bindings as napi, raw::Env};
pub unsafe fn set_instance_data<T: Send + 'static>(env: Env, data: T) -> *mut T {
let data = Box::into_raw(Box::new(data));

let () =
napi::set_instance_data(env, data.cast(), Some(drop_box::<T>), ptr::null_mut()).unwrap();
napi::set_instance_data(env, data.cast(), Some(drop_box::<T>), ptr::null_mut()).unwrap();

data
}
Expand All @@ -31,7 +30,7 @@ pub unsafe fn set_instance_data<T: Send + 'static>(env: Env, data: T) -> *mut T
pub unsafe fn get_instance_data<T: Send + 'static>(env: Env) -> *mut T {
let mut data = MaybeUninit::uninit();

let () = napi::get_instance_data(env, data.as_mut_ptr()).unwrap();
napi::get_instance_data(env, data.as_mut_ptr()).unwrap();

data.assume_init().cast()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/sys/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ use super::{

pub unsafe fn strict_equals(env: Env, lhs: Local, rhs: Local) -> bool {
let mut result = false;
let () = napi::strict_equals(env, lhs, rhs, &mut result as *mut _).unwrap();
napi::strict_equals(env, lhs, rhs, &mut result as *mut _).unwrap();
result
}
2 changes: 1 addition & 1 deletion crates/neon/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ unsafe fn string(env: Env, s: impl AsRef<str>) -> raw::Local {
let s = s.as_ref();
let mut result = MaybeUninit::uninit();

let () = create_string_utf8(
create_string_utf8(
env,
s.as_bytes().as_ptr() as *const _,
s.len(),
Expand Down
10 changes: 5 additions & 5 deletions crates/neon/src/sys/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use super::{

/// Mutates the `out` argument provided to refer to the global `undefined` object.
pub unsafe fn undefined(out: &mut Local, env: Env) {
let () = napi::get_undefined(env, out as *mut Local).unwrap();
napi::get_undefined(env, out as *mut Local).unwrap();
}

/// Mutates the `out` argument provided to refer to the global `null` object.
pub unsafe fn null(out: &mut Local, env: Env) {
let () = napi::get_null(env, out as *mut Local).unwrap();
napi::get_null(env, out as *mut Local).unwrap();
}

/// Mutates the `out` argument provided to refer to one of the global `true` or `false` objects.
pub unsafe fn boolean(out: &mut Local, env: Env, b: bool) {
let () = napi::get_boolean(env, b, out as *mut Local).unwrap();
napi::get_boolean(env, b, out as *mut Local).unwrap();
}

/// Get the boolean value out of a `Local` object. If the `Local` object does not contain a
Expand All @@ -32,13 +32,13 @@ pub unsafe fn boolean_value(env: Env, p: Local) -> bool {
/// Mutates the `out` argument provided to refer to a newly created `Local` containing a
/// JavaScript number.
pub unsafe fn number(out: &mut Local, env: Env, v: f64) {
let () = napi::create_double(env, v, out as *mut Local).unwrap();
napi::create_double(env, v, out as *mut Local).unwrap();
}

/// Gets the underlying value of an `Local` object containing a JavaScript number. Panics if
/// the given `Local` is not a number.
pub unsafe fn number_value(env: Env, p: Local) -> f64 {
let mut value = 0.0;
let () = napi::get_value_double(env, p, &mut value as *mut f64).unwrap();
napi::get_value_double(env, p, &mut value as *mut f64).unwrap();
value
}
8 changes: 4 additions & 4 deletions crates/neon/src/sys/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub unsafe fn create(env: Env) -> (napi::Deferred, napi::Value) {
let mut deferred = MaybeUninit::uninit();
let mut promise = MaybeUninit::uninit();

let () = napi::create_promise(env, deferred.as_mut_ptr(), promise.as_mut_ptr()).unwrap();
napi::create_promise(env, deferred.as_mut_ptr(), promise.as_mut_ptr()).unwrap();

(deferred.assume_init(), promise.assume_init())
}
Expand All @@ -26,7 +26,7 @@ pub unsafe fn create(env: Env) -> (napi::Deferred, napi::Value) {
/// * `env` is a valid `napi_env` for the current thread
/// * `resolution` is a valid `napi::Value`
pub unsafe fn resolve(env: Env, deferred: napi::Deferred, resolution: napi::Value) {
let () = napi::resolve_deferred(env, deferred, resolution).unwrap();
napi::resolve_deferred(env, deferred, resolution).unwrap();
}

/// Rejects a promise from a `napi::Deferred` handle
Expand All @@ -35,7 +35,7 @@ pub unsafe fn resolve(env: Env, deferred: napi::Deferred, resolution: napi::Valu
/// * `env` is a valid `napi_env` for the current thread
/// * `rejection` is a valid `napi::Value`
pub unsafe fn reject(env: Env, deferred: napi::Deferred, rejection: napi::Value) {
let () = napi::reject_deferred(env, deferred, rejection).unwrap();
napi::reject_deferred(env, deferred, rejection).unwrap();
}

#[cfg(feature = "napi-6")]
Expand All @@ -47,7 +47,7 @@ pub unsafe fn reject_err_message(env: Env, deferred: napi::Deferred, msg: impl A
let msg = super::string(env, msg);
let mut err = MaybeUninit::uninit();

let () = napi::create_error(env, std::ptr::null_mut(), msg, err.as_mut_ptr()).unwrap();
napi::create_error(env, std::ptr::null_mut(), msg, err.as_mut_ptr()).unwrap();

reject(env, deferred, err.assume_init());
}
Loading

0 comments on commit ad2cb8f

Please sign in to comment.