From 44ef4e1281482c5e68ee01f07fbe913f9f5057c5 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Fri, 8 May 2026 09:38:05 +0800 Subject: [PATCH] Apply clippy fixes --- src/error.rs | 2 +- src/ext/broadcast_channel/mod.rs | 2 +- src/ext/broadcast_channel/wrapper.rs | 33 ++++++++++++++-------------- src/ext/io/tty_unix.rs | 2 +- src/ext/runtime/mod.rs | 3 +-- src/ext/web/mod.rs | 3 ++- src/ext/web/permissions.rs | 6 ++--- src/inner_runtime.rs | 2 +- src/module_loader.rs | 2 +- src/op_whitelist.rs | 9 ++++++-- src/traits.rs | 4 +--- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7a4eeea4..44b1ac87 100644 --- a/src/error.rs +++ b/src/error.rs @@ -201,7 +201,7 @@ impl Error { }; // Combine all the parts - format!("{position_part}{source_line_part}{msg_part}",) + format!("{position_part}{source_line_part}{msg_part}") } else { self.to_string() }; diff --git a/src/ext/broadcast_channel/mod.rs b/src/ext/broadcast_channel/mod.rs index 9ec552cb..46b67d57 100644 --- a/src/ext/broadcast_channel/mod.rs +++ b/src/ext/broadcast_channel/mod.rs @@ -61,7 +61,7 @@ mod test { /// This test is identical to the original test from origin/master that verified /// JavaScript ↔ Rust bidirectional communication. /// - /// BroadcastChannelWrapper has been restored to maintain full backward compatibility + /// `BroadcastChannelWrapper` has been restored to maintain full backward compatibility /// with origin/master behavior. #[test] fn test_broadcast_channel() { diff --git a/src/ext/broadcast_channel/wrapper.rs b/src/ext/broadcast_channel/wrapper.rs index d635bd05..b9267045 100644 --- a/src/ext/broadcast_channel/wrapper.rs +++ b/src/ext/broadcast_channel/wrapper.rs @@ -20,7 +20,7 @@ //! //! ## Example //! -//! ### JavaScript ↔ Rust (BroadcastChannelWrapper) +//! ### JavaScript ↔ Rust (`BroadcastChannelWrapper`) //! ```rust,ignore //! use rustyscript::{BroadcastChannelWrapper, Runtime, RuntimeOptions}; //! @@ -35,7 +35,7 @@ //! // JavaScript BroadcastChannel('my_channel') receives this message //! ``` //! -//! ### Rust ↔ Rust (IsolatedBroadcastChannel) +//! ### Rust ↔ Rust (`IsolatedBroadcastChannel`) //! ```rust,ignore //! use rustyscript::{IsolatedBroadcastChannel, Runtime, RuntimeOptions}; //! @@ -61,7 +61,7 @@ use uuid::Uuid; use crate::{big_json_args, Error, Runtime}; -/// Message type matching deno_web's internal InMemoryChannelMessage structure +/// Message type matching `deno_web`'s internal `InMemoryChannelMessage` structure #[derive(Clone, Debug)] struct InMemoryChannelMessage { name: Arc, @@ -73,7 +73,7 @@ struct InMemoryChannelMessage { /// /// Takes care of some of the boilerplate for serialization/deserialization. /// Messages are serialized through the JavaScript runtime to ensure compatibility -/// with the JavaScript BroadcastChannel API. +/// with the JavaScript `BroadcastChannel` API. /// /// This wrapper shares the same underlying channel as JavaScript's `BroadcastChannel`, /// enabling bidirectional Rust ↔ JavaScript communication. @@ -91,7 +91,7 @@ pub struct BroadcastChannelWrapper { impl BroadcastChannelWrapper { /// Create a new broadcast channel wrapper and subscribe to the channel /// - /// This wrapper shares the same underlying channel as JavaScript's BroadcastChannel, + /// This wrapper shares the same underlying channel as JavaScript's `BroadcastChannel`, /// enabling bidirectional communication. /// /// Unsubscribe is called when the wrapper is dropped @@ -108,8 +108,7 @@ impl BroadcastChannelWrapper { // // We can access the field by transmuting to the inner type: let sender: &Arc>> = unsafe { - &*(channel as *const InMemoryBroadcastChannel - as *const Arc>>) + &*std::ptr::from_ref::(channel).cast::>>>() }; let sender = sender.clone(); @@ -180,6 +179,8 @@ impl BroadcastChannelWrapper { runtime: &mut Runtime, timeout: Option, ) -> Result, Error> { + use tokio::sync::broadcast::error::RecvError::{Closed, Lagged}; + let mut guard = self.receiver.lock().await; let (broadcast_rx, cancel_rx) = &mut *guard; @@ -197,12 +198,11 @@ impl BroadcastChannelWrapper { } }; - use tokio::sync::broadcast::error::RecvError::*; match result { Err(Closed) => return Ok(None), - Err(Lagged(_)) => continue, // Backlogged, messages dropped - try again - Ok(message) if message.uuid == self.uuid => continue, // Self-send, skip - Ok(message) if *message.name != self.name => continue, // Different channel name + Err(Lagged(_)) => {} // Backlogged, messages dropped - try again + Ok(message) if message.uuid == self.uuid => {} // Self-send, skip + Ok(message) if *message.name != self.name => {} // Different channel name Ok(message) => { // Deserialize through JavaScript for compatibility let data: T = runtime @@ -392,6 +392,8 @@ impl IsolatedBroadcastChannelWrapper { runtime: &mut Runtime, timeout: Option, ) -> Result, Error> { + use tokio::sync::broadcast::error::RecvError::{Closed, Lagged}; + let mut guard = self.receiver.lock().await; let (broadcast_rx, cancel_rx) = &mut *guard; @@ -409,12 +411,11 @@ impl IsolatedBroadcastChannelWrapper { } }; - use tokio::sync::broadcast::error::RecvError::*; match result { Err(Closed) => return Ok(None), - Err(Lagged(_)) => continue, // Backlogged, messages dropped - try again - Ok(message) if message.sender_id == self.uuid => continue, // Self-send, skip - Ok(message) if *message.name != self.name => continue, // Different channel name + Err(Lagged(_)) => {} // Backlogged, messages dropped - try again + Ok(message) if message.sender_id == self.uuid => {} // Self-send, skip + Ok(message) if *message.name != self.name => {} // Different channel name Ok(message) => { // Deserialize through JavaScript for compatibility let data: T = runtime @@ -464,7 +465,7 @@ impl Drop for IsolatedBroadcastChannelWrapper { #[cfg(test)] mod test { use super::*; - use crate::{Module, Runtime, RuntimeOptions}; + use crate::{Runtime, RuntimeOptions}; #[test] fn test_isolated_broadcast_channel_send_recv() { diff --git a/src/ext/io/tty_unix.rs b/src/ext/io/tty_unix.rs index f17dba78..06f9a532 100644 --- a/src/ext/io/tty_unix.rs +++ b/src/ext/io/tty_unix.rs @@ -203,7 +203,7 @@ fn console_size_from_fd(fd: std::os::unix::prelude::RawFd) -> Result Arc); -/// Convert WebPermissions to deno_permissions::PermissionsOptions +/// Convert `WebPermissions` to `deno_permissions::PermissionsOptions` /// -/// This function probes the WebPermissions trait methods to determine -/// what should be allowed, then converts to PermissionsOptions format. +/// This function probes the `WebPermissions` trait methods to determine +/// what should be allowed, then converts to `PermissionsOptions` format. /// /// - For `DefaultWebPermissions` (or equivalent allow-all): returns options that allow everything /// - For restrictive permissions (e.g., `AllowlistWebPermissions`): returns options that deny by default diff --git a/src/inner_runtime.rs b/src/inner_runtime.rs index 967a14e1..b871ce15 100644 --- a/src/inner_runtime.rs +++ b/src/inner_runtime.rs @@ -125,7 +125,7 @@ fn decode_args_to_globals( let len = arr.length(); let mut result = Vec::with_capacity(len as usize); for i in 0..len { - let index = v8::Integer::new(&context_scope, i as i32); + let index = v8::Integer::new(&context_scope, i.cast_signed()); if let Some(arg) = arr.get(&context_scope, index.into()) { let isolate: &v8::Isolate = &context_scope; result.push(v8::Global::new(isolate, arg)); diff --git a/src/module_loader.rs b/src/module_loader.rs index 3751cae2..dd6943e1 100644 --- a/src/module_loader.rs +++ b/src/module_loader.rs @@ -269,7 +269,7 @@ mod test { } } - /// Test backward compatibility for ImportProvider trait + /// Test backward compatibility for `ImportProvider` trait #[test] fn test_import_provider_backward_compat() { use deno_core::RequestedModuleType; diff --git a/src/op_whitelist.rs b/src/op_whitelist.rs index 9e88b2ec..d4808059 100644 --- a/src/op_whitelist.rs +++ b/src/op_whitelist.rs @@ -14,6 +14,7 @@ macro_rules! whitelist { } /// Get the global whitelist of ops. +#[must_use] pub fn get_whitelist() -> &'static OpWhitelist { &WHITELIST } @@ -243,11 +244,13 @@ whitelist!( pub struct OpWhitelist(&'static [OpSrc]); impl OpWhitelist { /// Create a new list of safe ops. + #[must_use] pub const fn new(ops: &'static [OpSrc]) -> Self { OpWhitelist(ops) } /// Check if the whitelist contains a specific op. + #[must_use] pub fn contains_op(&self, op: &str) -> bool { self.0.iter().any(|src| src.contains_op(op)) } @@ -274,7 +277,8 @@ pub struct OpSrc { pub stubs: &'static [&'static str], } impl OpSrc { - /// Create a new OpSrc. + /// Create a new `OpSrc`. + #[must_use] pub const fn new( src: &'static str, ops: &'static [&'static str], @@ -283,7 +287,8 @@ impl OpSrc { OpSrc { src, ops, stubs } } - /// Check if the OpSrc contains a specific op. + /// Check if the `OpSrc` contains a specific op. + #[must_use] pub fn contains_op(&self, op: &str) -> bool { self.ops.contains(&op) || self.stubs.contains(&op) } diff --git a/src/traits.rs b/src/traits.rs index 43dfb69a..d75b7fbe 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -75,9 +75,7 @@ impl ToV8String for str { // This is safe because the HandleScope is already on the stack and pinned. // This pattern is used throughout the codebase for V8 API compatibility. let scope_ref: &v8::PinnedRef> = unsafe { - std::mem::transmute::<&HandleScope<'a>, &v8::PinnedRef>>( - std::ptr::from_mut(scope).as_ref().unwrap(), - ) + &*std::ptr::from_mut(scope).cast::>>() }; v8::String::new(scope_ref, self).ok_or_else(|| Error::V8Encoding(self.to_string())) }