Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(neon): Fix clippy lints #1067

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/neon/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub trait Context<'a>: ContextInternal<'a> {
/// Lock the JavaScript engine, returning an RAII guard that keeps the lock active as long as the guard is alive.
///
/// If this is not the currently active context (for example, if it was used to spawn a scoped context with `execute_scoped` or `compute_scoped`), this method will panic.
fn lock<'b>(&'b mut self) -> Lock<Self>
fn lock<'b>(&'b mut self) -> Lock<'b, Self>
where
'a: 'b,
{
Expand Down Expand Up @@ -641,7 +641,7 @@ pub trait Context<'a>: ContextInternal<'a> {
/// Ok(promise)
/// }
/// ```
fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder<Self, E>
fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder<'cx, Self, E>
where
'a: 'cx,
O: Send + 'static,
Expand Down
12 changes: 6 additions & 6 deletions crates/neon/src/event/channel.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{
error, fmt, mem,
error, fmt,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
};

use crate::{
context::{Context, Cx},
context::{internal::Env, Context, Cx},
result::{NeonResult, ResultExt, Throw},
sys::{raw::Env, tsfn::ThreadsafeFunction},
sys::{self, tsfn::ThreadsafeFunction},
};

#[cfg(feature = "futures")]
Expand Down Expand Up @@ -44,7 +44,7 @@ mod oneshot {
}
}

type Callback = Box<dyn FnOnce(Env) + Send + 'static>;
type Callback = Box<dyn FnOnce(sys::Env) + Send + 'static>;

/// Channel for scheduling Rust closures to execute on the JavaScript main thread.
///
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Channel {
{
let (tx, rx) = oneshot::channel();
let callback = Box::new(move |env| {
let env = unsafe { mem::transmute(env) };
let env = Env::from(env);

// Note: It is sufficient to use `Cx` because
// N-API creates a `HandleScope` before calling the callback.
Expand Down Expand Up @@ -409,7 +409,7 @@ impl ChannelState {
}

// Monomorphized trampoline funciton for calling the user provided closure
fn callback(env: Option<Env>, callback: Callback) {
fn callback(env: Option<sys::Env>, callback: Callback) {
if let Some(env) = env {
callback(env);
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, F: Value, T: Value> ResultExt<Handle<'a, T>> for DowncastResult<'a, F,
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> {
match self {
Ok(v) => Ok(v),
Err(e) => cx.throw_type_error(&e.to_string()),
Err(e) => cx.throw_type_error(e.to_string()),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/neon/src/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl LocalCell {
}
}

pub(crate) fn get<'cx, 'a, C>(cx: &'a mut C, id: usize) -> Option<&mut LocalCellValue>
pub(crate) fn get<'cx, 'a, C>(cx: &'a mut C, id: usize) -> Option<&'a mut LocalCellValue>
where
C: Context<'cx>,
{
Expand All @@ -113,7 +113,11 @@ impl LocalCell {
}
}

pub(crate) fn get_or_init<'cx, 'a, C, F>(cx: &'a mut C, id: usize, f: F) -> &mut LocalCellValue
pub(crate) fn get_or_init<'cx, 'a, C, F>(
cx: &'a mut C,
id: usize,
f: F,
) -> &'a mut LocalCellValue
where
C: Context<'cx>,
F: FnOnce() -> LocalCellValue,
Expand All @@ -129,7 +133,7 @@ impl LocalCell {
cx: &'a mut C,
id: usize,
f: F,
) -> Result<&mut LocalCellValue, E>
) -> Result<&'a mut LocalCellValue, E>
where
C: Context<'cx>,
F: FnOnce(&mut C) -> Result<LocalCellValue, E>,
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<T: Finalize + 'static> JsBox<T> {
// contained value `T`.
fn finalizer<U: Finalize + 'static>(env: raw::Env, data: BoxAny) {
let data = *data.downcast::<U>().unwrap();
let env = unsafe { std::mem::transmute(env) };
let env = Env::from(env);

Cx::with_context(env, move |mut cx| data.finalize(&mut cx));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/extract/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn json_stringify<'cx>(cx: &mut Cx<'cx>) -> JsResult<'cx, JsFunction> {
.map(|f| f.to_inner(cx))
}

fn stringify<'cx>(cx: &mut Cx<'cx>, v: Handle<JsValue>) -> NeonResult<String> {
fn stringify(cx: &mut Cx, v: Handle<JsValue>) -> NeonResult<String> {
json_stringify(cx)?
.call(cx, v, [v])?
.downcast_or_throw::<JsString, _>(cx)
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/extract/try_from_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'cx> TryFromJs<'cx> for ArrayBuffer {
from_js!();
}

fn is_null_or_undefined<'cx, V>(cx: &mut Cx<'cx>, v: Handle<V>) -> NeonResult<bool>
fn is_null_or_undefined<V>(cx: &mut Cx, v: Handle<V>) -> NeonResult<bool>
where
V: Value,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl<'a> ResultExt<Handle<'a, JsString>> for StringResult<'a> {
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, JsString> {
match self {
Ok(v) => Ok(v),
Err(e) => cx.throw_range_error(&e.to_string()),
Err(e) => cx.throw_range_error(e.to_string()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

const SMALL_MAX: usize = std::i32::MAX as usize;
const SMALL_MAX: usize = i32::MAX as usize;

/// V8 APIs that take UTF-8 strings take their length in the form of 32-bit
/// signed integers. This type represents a UTF-8 string that contains no
Expand Down
2 changes: 1 addition & 1 deletion test/napi/src/js/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> {

RUNTIME
.get_or_try_init(Runtime::new)
.or_else(|err| cx.throw_error(&err.to_string()))
.or_else(|err| cx.throw_error(err.to_string()))
}

// Accepts two functions that take no parameters and return numbers.
Expand Down
2 changes: 1 addition & 1 deletion test/napi/src/js/typedarrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ where
Ok(obj)
}

fn detach_and_then<'cx, F>(mut cx: FunctionContext<'cx>, f: F) -> JsResult<JsObject>
fn detach_and_then<'cx, F>(mut cx: FunctionContext<'cx>, f: F) -> JsResult<'cx, JsObject>
where
F: FnOnce(
&mut FunctionContext<'cx>,
Expand Down