Skip to content

Commit

Permalink
Switched to #[expect] Attributes
Browse files Browse the repository at this point in the history
Fixed Some Lints
  • Loading branch information
Redfire75369 committed Sep 8, 2024
1 parent 72e1778 commit 610b1b6
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 60 deletions.
2 changes: 1 addition & 1 deletion ion/examples/macros/js_fn/complex.rs
Original file line number Diff line number Diff line change
@@ -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<i8>, Strict(_boolean): Strict<bool>,
Expand Down
4 changes: 1 addition & 3 deletions ion/src/class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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) })
Expand Down
26 changes: 16 additions & 10 deletions ion/src/class/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,33 +14,40 @@ 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<T: 'static> Sealed for super::TypeIdWrapper<T> {}
impl<T: 'static> Sealed for super::TypeIdWrapper<T> {
fn type_id(&self) -> TypeId {
TypeId::of::<T>()
}
}
}

pub struct TypeIdWrapper<T: 'static> {
_private: PhantomData<T>,
}

impl<T: 'static> TypeIdWrapper<T> {
#[allow(clippy::new_without_default)]
pub const fn new() -> TypeIdWrapper<T> {
TypeIdWrapper { _private: PhantomData }
}
}

impl<T: 'static> TypeIdWrap for TypeIdWrapper<T> {
fn type_id(&self) -> TypeId {
TypeId::of::<T>()
impl<T: 'static> Default for TypeIdWrapper<T> {
fn default() -> TypeIdWrapper<T> {
TypeIdWrapper::new()
}
}

impl<T: 'static> TypeIdWrap for TypeIdWrapper<T> {}

unsafe impl<T: 'static> Send for TypeIdWrapper<T> {}

unsafe impl<T: 'static> Sync for TypeIdWrapper<T> {}
Expand Down
45 changes: 21 additions & 24 deletions ion/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -39,20 +37,6 @@ pub enum GCType {
Symbol,
}

/// Holds Rooted Values
#[derive(Default)]
struct RootedArena {
values: Arena<Rooted<JSVal>>,
objects: Arena<Rooted<*mut JSObject>>,
strings: Arena<Rooted<*mut JSString>>,
scripts: Arena<Rooted<*mut JSScript>>,
property_keys: Arena<Rooted<PropertyKey>>,
property_descriptors: Arena<Rooted<PropertyDescriptor>>,
functions: Arena<Rooted<*mut JSFunction>>,
big_ints: Arena<Rooted<*mut BigInt>>,
symbols: Arena<Rooted<*mut Symbol>>,
}

pub trait TraceablePrivate: Traceable + Any {
fn as_any(&self) -> &dyn Any;

Expand Down Expand Up @@ -172,13 +156,27 @@ pub trait Rootable: private::Sealed {}
impl<T: private::Sealed> 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<Rooted<JSVal>>,
pub objects: Arena<Rooted<*mut JSObject>>,
pub strings: Arena<Rooted<*mut JSString>>,
pub scripts: Arena<Rooted<*mut JSScript>>,
pub property_keys: Arena<Rooted<PropertyKey>>,
pub property_descriptors: Arena<Rooted<PropertyDescriptor>>,
pub functions: Arena<Rooted<*mut JSFunction>>,
pub big_ints: Arena<Rooted<*mut BigInt>>,
pub symbols: Arena<Rooted<*mut Symbol>>,
}

#[expect(clippy::mut_from_ref)]
pub trait Sealed: RootKind + GCMethods + Copy + Sized {
const GC_TYPE: GCType;

Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions ion/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module<'cx>, ModuleError> {
Expand Down Expand Up @@ -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<Promise<'cx>>), ModuleError> {
Expand Down
8 changes: 6 additions & 2 deletions ion/src/object/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions ion/src/object/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions ion/src/object/typedarray/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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) }
}
Expand Down
4 changes: 2 additions & 2 deletions ion/src/object/typedarray/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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) }
}
Expand Down
7 changes: 6 additions & 1 deletion ion/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub struct ArrayVec<const CAP: usize, T: Copy> {
}

impl<const CAP: usize, T: Copy> ArrayVec<CAP, T> {
#[allow(clippy::new_without_default)]
pub const fn new() -> ArrayVec<CAP, T> {
ArrayVec {
elements: unsafe { MaybeUninit::uninit().assume_init() },
Expand Down Expand Up @@ -117,6 +116,12 @@ impl<const CAP: usize, T: Copy> ArrayVec<CAP, T> {
}
}

impl<const CAP: usize, T: Copy> Default for ArrayVec<CAP, T> {
fn default() -> ArrayVec<CAP, T> {
ArrayVec::new()
}
}

pub mod test {
use mozjs::jsapi::{JSAutoRealm, JSObject};
use mozjs::rust::{JSEngine, Runtime};
Expand Down
4 changes: 2 additions & 2 deletions modules/src/fs/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion runtime/src/globals/fetch/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub struct Request {

pub(crate) integrity: String,

#[allow(dead_code)]
pub(crate) unsafe_request: bool,
pub(crate) keepalive: bool,

Expand Down
8 changes: 4 additions & 4 deletions runtime/src/globals/fetch/request/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub enum RequestMode {
#[default]
NoCors,
Navigate,
#[allow(dead_code)]
#[expect(dead_code)]
Websocket,
}

Expand Down Expand Up @@ -400,9 +400,9 @@ pub struct RequestInit<'cx> {
pub(crate) keepalive: Option<bool>,
pub(crate) signal: Option<*mut JSObject>,

#[allow(dead_code)]
#[expect(dead_code)]
pub(crate) duplex: Option<RequestDuplex>,
#[allow(dead_code)]
#[expect(dead_code)]
#[ion(default)]
priority: Option<RequestPriority>,
pub(crate) window: Option<JSVal>,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/globals/url/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/globals/url/search_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
}

Expand Down

0 comments on commit 610b1b6

Please sign in to comment.