From 610b1b6fd994c75bd3741c7e5110275590329db0 Mon Sep 17 00:00:00 2001 From: Redfire Date: Sun, 8 Sep 2024 21:03:27 +0800 Subject: [PATCH] Switched to #[expect] Attributes Fixed Some Lints --- ion/examples/macros/js_fn/complex.rs | 2 +- ion/src/class/mod.rs | 4 +- ion/src/class/native.rs | 26 ++++++----- ion/src/context.rs | 45 +++++++++----------- ion/src/module.rs | 4 +- ion/src/object/array.rs | 8 +++- ion/src/object/object.rs | 4 +- ion/src/object/typedarray/buffer.rs | 4 +- ion/src/object/typedarray/view.rs | 4 +- ion/src/utils.rs | 7 ++- modules/src/fs/fs.rs | 4 +- runtime/src/globals/fetch/request/mod.rs | 1 - runtime/src/globals/fetch/request/options.rs | 8 ++-- runtime/src/globals/url/mod.rs | 2 +- runtime/src/globals/url/search_params.rs | 2 +- runtime/src/runtime.rs | 4 +- 16 files changed, 69 insertions(+), 60 deletions(-) diff --git a/ion/examples/macros/js_fn/complex.rs b/ion/examples/macros/js_fn/complex.rs index 1a5a0384..7103e6e5 100644 --- a/ion/examples/macros/js_fn/complex.rs +++ b/ion/examples/macros/js_fn/complex.rs @@ -1,7 +1,7 @@ use ion::function::{Enforce, Rest, Strict}; use ion::{js_fn, Context, Function, Object, Promise, Value}; -#[allow(clippy::too_many_arguments)] +#[expect(clippy::too_many_arguments)] #[js_fn] pub fn many_inputs( _cx: &Context, #[ion(this)] _this: &Object, Enforce(_integer): Enforce, Strict(_boolean): Strict, diff --git a/ion/src/class/mod.rs b/ion/src/class/mod.rs index b26f6164..8e7f31fd 100644 --- a/ion/src/class/mod.rs +++ b/ion/src/class/mod.rs @@ -28,7 +28,7 @@ mod native; mod reflect; /// Stores information about a native class created for JS. -#[allow(dead_code)] +#[expect(dead_code)] #[derive(Debug)] pub struct ClassInfo { class: &'static NativeClass, @@ -154,7 +154,6 @@ pub trait ClassDefinition: NativeObject { } } - #[allow(clippy::mut_from_ref)] unsafe fn get_mut_private_unchecked<'a>(object: &Object<'a>) -> &'a mut Self { unsafe { let mut value = UndefinedValue(); @@ -163,7 +162,6 @@ pub trait ClassDefinition: NativeObject { } } - #[allow(clippy::mut_from_ref)] fn get_mut_private<'a>(cx: &Context, object: &Object<'a>) -> Result<&'a mut Self> { if Self::instance_of(cx, object) || Self::has_instance(cx, object)? { Ok(unsafe { Self::get_mut_private_unchecked(object) }) diff --git a/ion/src/class/native.rs b/ion/src/class/native.rs index 8e757095..1addf49b 100644 --- a/ion/src/class/native.rs +++ b/ion/src/class/native.rs @@ -4,7 +4,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::any::TypeId; use std::fmt; use std::fmt::{Debug, Formatter, Write}; use std::marker::PhantomData; @@ -15,14 +14,20 @@ use crate::utils::ArrayVec; pub const MAX_PROTO_CHAIN_LENGTH: usize = 8; -pub trait TypeIdWrap: private::Sealed + 'static { - fn type_id(&self) -> TypeId; -} +pub trait TypeIdWrap: private::Sealed + 'static {} mod private { - pub trait Sealed {} + use std::any::TypeId; + + pub trait Sealed: 'static { + fn type_id(&self) -> TypeId; + } - impl Sealed for super::TypeIdWrapper {} + impl Sealed for super::TypeIdWrapper { + fn type_id(&self) -> TypeId { + TypeId::of::() + } + } } pub struct TypeIdWrapper { @@ -30,18 +35,19 @@ pub struct TypeIdWrapper { } impl TypeIdWrapper { - #[allow(clippy::new_without_default)] pub const fn new() -> TypeIdWrapper { TypeIdWrapper { _private: PhantomData } } } -impl TypeIdWrap for TypeIdWrapper { - fn type_id(&self) -> TypeId { - TypeId::of::() +impl Default for TypeIdWrapper { + fn default() -> TypeIdWrapper { + TypeIdWrapper::new() } } +impl TypeIdWrap for TypeIdWrapper {} + unsafe impl Send for TypeIdWrapper {} unsafe impl Sync for TypeIdWrapper {} diff --git a/ion/src/context.rs b/ion/src/context.rs index 8f7628b1..0ff77ae4 100644 --- a/ion/src/context.rs +++ b/ion/src/context.rs @@ -13,17 +13,15 @@ use std::ptr::NonNull; use mozjs::gc::{GCMethods, Traceable}; use mozjs::jsapi::{ - BigInt, JSContext, JSFunction, JSObject, JSScript, JSString, JSTracer, JS_AddExtraGCRootsTracer, - JS_GetContextPrivate, JS_RemoveExtraGCRootsTracer, JS_SetContextPrivate, PropertyDescriptor, PropertyKey, Rooted, - Symbol, + JSContext, JSTracer, JS_AddExtraGCRootsTracer, JS_GetContextPrivate, JS_RemoveExtraGCRootsTracer, + JS_SetContextPrivate, Rooted, }; -use mozjs::jsval::JSVal; use mozjs::rust::Runtime; -use typed_arena::Arena; use crate::class::ClassInfo; use crate::module::ModuleLoader; use crate::Local; +use private::RootedArena; /// Represents Types that can be Rooted in SpiderMonkey #[derive(Clone, Copy, Debug)] @@ -39,20 +37,6 @@ pub enum GCType { Symbol, } -/// Holds Rooted Values -#[derive(Default)] -struct RootedArena { - values: Arena>, - objects: Arena>, - strings: Arena>, - scripts: Arena>, - property_keys: Arena>, - property_descriptors: Arena>, - functions: Arena>, - big_ints: Arena>, - symbols: Arena>, -} - pub trait TraceablePrivate: Traceable + Any { fn as_any(&self) -> &dyn Any; @@ -172,13 +156,27 @@ pub trait Rootable: private::Sealed {} impl Rootable for T {} mod private { + use super::GCType; use mozjs::gc::{GCMethods, RootKind}; use mozjs::jsapi::{BigInt, JSFunction, JSObject, JSScript, JSString, PropertyDescriptor, PropertyKey, Rooted, Symbol}; use mozjs::jsval::JSVal; - - use super::{GCType, RootedArena}; - - #[allow(clippy::mut_from_ref, private_interfaces)] + use typed_arena::Arena; + + /// Holds Rooted Values + #[derive(Default)] + pub struct RootedArena { + pub values: Arena>, + pub objects: Arena>, + pub strings: Arena>, + pub scripts: Arena>, + pub property_keys: Arena>, + pub property_descriptors: Arena>, + pub functions: Arena>, + pub big_ints: Arena>, + pub symbols: Arena>, + } + + #[expect(clippy::mut_from_ref)] pub trait Sealed: RootKind + GCMethods + Copy + Sized { const GC_TYPE: GCType; @@ -188,7 +186,6 @@ mod private { macro_rules! impl_rootable { ($(($value:ty, $key:ident, $gc_type:ident)$(,)?)*) => { $( - #[allow(clippy::mut_from_ref, private_interfaces)] impl Sealed for $value { const GC_TYPE: GCType = GCType::$gc_type; diff --git a/ion/src/module.rs b/ion/src/module.rs index d605cd3c..447524b7 100644 --- a/ion/src/module.rs +++ b/ion/src/module.rs @@ -99,7 +99,7 @@ pub struct Module<'m>(pub Object<'m>); impl<'cx> Module<'cx> { /// Compiles a [Module] with the given source and filename. - #[allow(clippy::result_large_err)] + #[expect(clippy::result_large_err)] pub fn compile( cx: &'cx Context, filename: &str, path: Option<&Path>, script: &str, ) -> Result, ModuleError> { @@ -134,7 +134,7 @@ impl<'cx> Module<'cx> { /// Compiles and evaluates a [Module] with the given source and filename. /// On success, returns the compiled module object and a promise. The promise resolves with the return value of the module. /// The promise is a byproduct of enabling top-level await. - #[allow(clippy::result_large_err)] + #[expect(clippy::result_large_err)] pub fn compile_and_evaluate( cx: &'cx Context, filename: &str, path: Option<&Path>, script: &str, ) -> Result<(Module<'cx>, Option>), ModuleError> { diff --git a/ion/src/object/array.rs b/ion/src/object/array.rs index 47283e49..0260c0d7 100644 --- a/ion/src/object/array.rs +++ b/ion/src/object/array.rs @@ -79,7 +79,6 @@ impl<'a> Array<'a> { } /// Returns the length of the [Array]. - #[allow(clippy::len_without_is_empty)] pub fn len(&self, cx: &Context) -> u32 { let mut length = 0; unsafe { @@ -88,6 +87,11 @@ impl<'a> Array<'a> { length } + /// Returns if the [Array] is empty. + pub fn is_empty(&self, cx: &Context) -> bool { + self.len(cx) == 0 + } + /// Checks if the [Array] has a value at the given index. pub fn has(&self, cx: &Context, index: u32) -> bool { self.arr.has(cx, index) @@ -266,9 +270,9 @@ impl FusedIterator for ArrayIter<'_, '_> {} #[cfg(test)] mod tests { - use crate::{Array, Value}; use crate::flags::PropertyFlags; use crate::utils::test::TestRuntime; + use crate::{Array, Value}; #[test] fn array() { diff --git a/ion/src/object/object.rs b/ion/src/object/object.rs index 9ec06f4a..56006497 100644 --- a/ion/src/object/object.rs +++ b/ion/src/object/object.rs @@ -479,11 +479,11 @@ impl FusedIterator for ObjectIter<'_, '_> {} #[cfg(test)] mod tests { + use crate::conversions::FromValue; use crate::flags::{IteratorFlags, PropertyFlags}; + use crate::symbol::WellKnownSymbolCode; use crate::utils::test::TestRuntime; use crate::{Context, Object, OwnedKey, Symbol, Value}; - use crate::conversions::FromValue; - use crate::symbol::WellKnownSymbolCode; type Property = (&'static str, i32); diff --git a/ion/src/object/typedarray/buffer.rs b/ion/src/object/typedarray/buffer.rs index ea50fe74..ab72da51 100644 --- a/ion/src/object/typedarray/buffer.rs +++ b/ion/src/object/typedarray/buffer.rs @@ -111,7 +111,7 @@ impl<'ab> ArrayBuffer<'ab> { /// Returns a mutable slice to the contents of the [ArrayBuffer]. /// /// The slice may be invalidated if the [ArrayBuffer] is detached. - #[allow(clippy::mut_from_ref)] + #[expect(clippy::mut_from_ref)] pub unsafe fn as_mut_slice(&self) -> &mut [u8] { let (ptr, len, _) = self.data(); unsafe { slice::from_raw_parts_mut(ptr, len) } @@ -170,7 +170,7 @@ impl<'ab> ArrayBuffer<'ab> { } /// Checks if an object is an array buffer. - #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[expect(clippy::not_unsafe_ptr_arg_deref)] pub fn is_array_buffer(object: *mut JSObject) -> bool { unsafe { IsArrayBufferObjectMaybeShared(object) } } diff --git a/ion/src/object/typedarray/view.rs b/ion/src/object/typedarray/view.rs index 8a1399aa..8389df17 100644 --- a/ion/src/object/typedarray/view.rs +++ b/ion/src/object/typedarray/view.rs @@ -193,7 +193,7 @@ impl<'bv, T: TypedArrayElement> TypedArray<'bv, T> { /// Returns a mutable slice to the contents of the [TypedArray]. /// /// The slice may be invalidated if the underlying [ArrayBuffer] is detached. - #[allow(clippy::mut_from_ref)] + #[expect(clippy::mut_from_ref)] pub unsafe fn as_mut_slice(&self) -> &mut [T::Element] { let (ptr, len) = self.data(); unsafe { slice::from_raw_parts_mut(ptr, len) } @@ -233,7 +233,7 @@ impl<'bv, T: TypedArrayElement> TypedArray<'bv, T> { } /// Checks if an object is an array buffer view. - #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[expect(clippy::not_unsafe_ptr_arg_deref)] pub fn is_array_buffer_view(object: *mut JSObject) -> bool { unsafe { JS_IsArrayBufferViewObject(object) } } diff --git a/ion/src/utils.rs b/ion/src/utils.rs index 79187d16..a363e78b 100644 --- a/ion/src/utils.rs +++ b/ion/src/utils.rs @@ -59,7 +59,6 @@ pub struct ArrayVec { } impl ArrayVec { - #[allow(clippy::new_without_default)] pub const fn new() -> ArrayVec { ArrayVec { elements: unsafe { MaybeUninit::uninit().assume_init() }, @@ -117,6 +116,12 @@ impl ArrayVec { } } +impl Default for ArrayVec { + fn default() -> ArrayVec { + ArrayVec::new() + } +} + pub mod test { use mozjs::jsapi::{JSAutoRealm, JSObject}; use mozjs::rust::{JSEngine, Runtime}; diff --git a/modules/src/fs/fs.rs b/modules/src/fs/fs.rs index a78c70f9..1c625f27 100644 --- a/modules/src/fs/fs.rs +++ b/modules/src/fs/fs.rs @@ -4,11 +4,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use futures::stream::StreamExt; +use mozjs::jsapi::JSFunctionSpec; use std::iter::Iterator; use std::path::Path; use std::{fs, io, os}; -use futures::stream::StreamExt; -use mozjs::jsapi::JSFunctionSpec; use tokio_stream::wrappers::ReadDirStream; use ion::flags::PropertyFlags; diff --git a/runtime/src/globals/fetch/request/mod.rs b/runtime/src/globals/fetch/request/mod.rs index d0e77cf0..cc2d1c5f 100644 --- a/runtime/src/globals/fetch/request/mod.rs +++ b/runtime/src/globals/fetch/request/mod.rs @@ -55,7 +55,6 @@ pub struct Request { pub(crate) integrity: String, - #[allow(dead_code)] pub(crate) unsafe_request: bool, pub(crate) keepalive: bool, diff --git a/runtime/src/globals/fetch/request/options.rs b/runtime/src/globals/fetch/request/options.rs index baa06d25..5cbb3dab 100644 --- a/runtime/src/globals/fetch/request/options.rs +++ b/runtime/src/globals/fetch/request/options.rs @@ -20,7 +20,7 @@ use crate::globals::fetch::header::HeadersInit; #[derive(Clone, Default, Debug, Traceable)] pub enum Referrer { - #[allow(clippy::enum_variant_names)] + #[expect(clippy::enum_variant_names)] NoReferrer, #[default] Client, @@ -134,7 +134,7 @@ pub enum RequestMode { #[default] NoCors, Navigate, - #[allow(dead_code)] + #[expect(dead_code)] Websocket, } @@ -400,9 +400,9 @@ pub struct RequestInit<'cx> { pub(crate) keepalive: Option, pub(crate) signal: Option<*mut JSObject>, - #[allow(dead_code)] + #[expect(dead_code)] pub(crate) duplex: Option, - #[allow(dead_code)] + #[expect(dead_code)] #[ion(default)] priority: Option, pub(crate) window: Option, diff --git a/runtime/src/globals/url/mod.rs b/runtime/src/globals/url/mod.rs index e9f57231..5e58125b 100644 --- a/runtime/src/globals/url/mod.rs +++ b/runtime/src/globals/url/mod.rs @@ -140,7 +140,7 @@ impl URL { } #[ion(name = "toString", alias = ["toJSON"])] - #[allow(clippy::inherent_to_string)] + #[expect(clippy::inherent_to_string)] pub fn to_string(&self) -> String { self.url.to_string() } diff --git a/runtime/src/globals/url/search_params.rs b/runtime/src/globals/url/search_params.rs index 8493b839..c46e4772 100644 --- a/runtime/src/globals/url/search_params.rs +++ b/runtime/src/globals/url/search_params.rs @@ -168,7 +168,7 @@ impl URLSearchParams { } #[ion(name = "toString")] - #[allow(clippy::inherent_to_string)] + #[expect(clippy::inherent_to_string)] pub fn to_string(&self) -> String { Serializer::new(String::new()).extend_pairs(&*self.pairs).finish() } diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index bc65cfc9..5c05a415 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -42,7 +42,7 @@ unsafe impl Traceable for ContextPrivate { } pub trait ContextExt { - #[allow(clippy::mut_from_ref)] + #[expect(clippy::mut_from_ref)] unsafe fn get_private(&self) -> &mut ContextPrivate; } @@ -55,7 +55,7 @@ impl ContextExt for Context { pub struct Runtime<'cx> { global: Object<'cx>, cx: &'cx Context, - #[allow(dead_code)] + #[expect(dead_code)] realm: JSAutoRealm, }