Browse Source

Apply new clippy lints for rustc 1.77 (#3759)

* First bump fixes

* Apply automatic clippy lints

* cargo fmt

* Apply manual lints
pull/3758/head
José Julián Espina 7 months ago committed by GitHub
parent
commit
03d972957d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      Cargo.toml
  2. 1
      cli/src/main.rs
  3. 3
      core/engine/src/builtins/array_buffer/mod.rs
  4. 2
      core/engine/src/builtins/number/globals.rs
  5. 1
      core/engine/src/builtins/typed_array/element/mod.rs
  6. 9
      core/engine/src/builtins/typed_array/object.rs
  7. 2
      core/engine/src/context/mod.rs
  8. 2
      core/engine/src/module/source.rs
  9. 2
      core/engine/src/object/internal_methods/mod.rs
  10. 8
      core/engine/src/object/shape/shared_shape/forward_transition.rs
  11. 20
      core/engine/src/string/mod.rs
  12. 2
      core/gc/src/lib.rs
  13. 1
      examples/Cargo.toml
  14. 2
      tests/macros/tests/derive/from_js_with.rs
  15. 2
      tests/macros/tests/derive/simple_struct.rs
  16. 2
      tests/macros/tests/tests.rs
  17. 3
      tests/tester/src/exec/mod.rs
  18. 3
      tests/tester/src/main.rs

1
Cargo.toml

@ -163,7 +163,6 @@ unused_crate_dependencies = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"
[workspace.lints.rustdoc]

1
cli/src/main.rs

@ -376,6 +376,7 @@ fn main() -> Result<(), io::Error> {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(CLI_HISTORY)?;
editor.load_history(CLI_HISTORY).map_err(|err| match err {
ReadlineError::Io(e) => e,

3
core/engine/src/builtins/array_buffer/mod.rs

@ -425,8 +425,7 @@ impl ArrayBuffer {
Ok(args
.get_or_undefined(0)
.as_object()
.map(|obj| obj.is::<TypedArray>() || obj.is::<DataView>())
.unwrap_or_default()
.is_some_and(|obj| obj.is::<TypedArray>() || obj.is::<DataView>())
.into())
}

2
core/engine/src/builtins/number/globals.rs

@ -172,7 +172,7 @@ pub(crate) fn parse_int(_: &JsValue, args: &[JsValue], context: &mut Context) ->
// 11. If S contains a code unit that is not a radix-R digit, let end be the index within S of the
// first such code unit; otherwise, let end be the length of S.
let end = char::decode_utf16(var_s.iter().copied())
.position(|code| !code.map(|c| c.is_digit(var_r as u32)).unwrap_or_default())
.position(|code| !code.is_ok_and(|c| c.is_digit(var_r as u32)))
.unwrap_or(var_s.len());
// 12. Let Z be the substring of S from 0 to end.

1
core/engine/src/builtins/typed_array/element/mod.rs

@ -1,6 +1,5 @@
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(clippy::cast_ptr_alignment)] // Invariants are checked by the caller.
#![allow(unused_tuple_struct_fields)] // Weird false-positive with `boa_macros_tests`
mod atomic;

9
core/engine/src/builtins/typed_array/object.rs

@ -579,12 +579,9 @@ fn typed_array_get_element(obj: &JsObject, index: f64) -> Option<JsValue> {
let buffer = buffer.as_buffer();
// 1. If IsValidIntegerIndex(O, index) is false, return undefined.
let Some(buffer) = buffer.bytes(Ordering::Relaxed) else {
return None;
};
let Some(index) = inner.validate_index(index, buffer.len()) else {
return None;
};
let buffer = buffer.bytes(Ordering::Relaxed)?;
let index = inner.validate_index(index, buffer.len())?;
// 2. Let offset be O.[[ByteOffset]].
let offset = inner.byte_offset();

2
core/engine/src/context/mod.rs

@ -39,7 +39,7 @@ use crate::vm::RuntimeLimits;
use self::intrinsics::StandardConstructor;
thread_local! {
static CANNOT_BLOCK_COUNTER: Cell<u64> = Cell::new(0);
static CANNOT_BLOCK_COUNTER: Cell<u64> = const { Cell::new(0) };
}
/// ECMAScript context. It is the primary way to interact with the runtime.

2
core/engine/src/module/source.rs

@ -1001,7 +1001,7 @@ impl SourceTextModule {
/// Returns an error if there's no more available indices.
fn get_async_eval_index() -> JsResult<usize> {
thread_local! {
static ASYNC_EVAL_QUEUE_INDEX: Cell<usize> = Cell::new(0);
static ASYNC_EVAL_QUEUE_INDEX: Cell<usize> = const { Cell::new(0) };
}
ASYNC_EVAL_QUEUE_INDEX

2
core/engine/src/object/internal_methods/mod.rs

@ -412,7 +412,7 @@ pub(crate) fn ordinary_get_prototype_of(
let _timer = Profiler::global().start_event("Object::ordinary_get_prototype_of", "object");
// 1. Return O.[[Prototype]].
Ok(obj.prototype().as_ref().cloned())
Ok(obj.prototype().clone())
}
/// Abstract operation `OrdinarySetPrototypeOf`.

8
core/engine/src/object/shape/shared_shape/forward_transition.rs

@ -80,18 +80,14 @@ impl ForwardTransition {
/// Get a property transition, return [`None`] otherwise.
pub(super) fn get_property(&self, key: &TransitionKey) -> Option<WeakGc<SharedShapeInner>> {
let this = self.inner.borrow();
let Some(transitions) = this.properties.as_ref() else {
return None;
};
let transitions = this.properties.as_ref()?;
transitions.map.get(key).cloned()
}
/// Get a prototype transition, return [`None`] otherwise.
pub(super) fn get_prototype(&self, key: &JsPrototype) -> Option<WeakGc<SharedShapeInner>> {
let this = self.inner.borrow();
let Some(transitions) = this.prototypes.as_ref() else {
return None;
};
let transitions = this.prototypes.as_ref()?;
transitions.map.get(key).cloned()
}

20
core/engine/src/string/mod.rs

@ -868,22 +868,22 @@ pub(crate) trait Utf16Trim {
impl Utf16Trim for [u16] {
fn trim_start(&self) -> &Self {
if let Some(left) = self.iter().copied().position(|r| {
!char::from_u32(u32::from(r))
.map(is_trimmable_whitespace)
.unwrap_or_default()
}) {
if let Some(left) = self
.iter()
.copied()
.position(|r| !char::from_u32(u32::from(r)).is_some_and(is_trimmable_whitespace))
{
&self[left..]
} else {
&[]
}
}
fn trim_end(&self) -> &Self {
if let Some(right) = self.iter().copied().rposition(|r| {
!char::from_u32(u32::from(r))
.map(is_trimmable_whitespace)
.unwrap_or_default()
}) {
if let Some(right) = self
.iter()
.copied()
.rposition(|r| !char::from_u32(u32::from(r)).is_some_and(is_trimmable_whitespace))
{
&self[..=right]
} else {
&[]

2
core/gc/src/lib.rs

@ -42,7 +42,7 @@ type GcErasedPointer = NonNull<GcBox<NonTraceable>>;
type EphemeronPointer = NonNull<dyn ErasedEphemeronBox>;
type ErasedWeakMapBoxPointer = NonNull<dyn ErasedWeakMapBox>;
thread_local!(static GC_DROPPING: Cell<bool> = Cell::new(false));
thread_local!(static GC_DROPPING: Cell<bool> = const { Cell::new(false) });
thread_local!(static BOA_GC: RefCell<BoaGc> = RefCell::new( BoaGc {
config: GcConfig::default(),
runtime: GcRuntimeData::default(),

1
examples/Cargo.toml

@ -47,7 +47,6 @@ unsafe_op_in_unsafe_fn = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"
[lints.clippy]

2
tests/macros/tests/derive/from_js_with.rs

@ -1,4 +1,4 @@
#![allow(unused, unused_tuple_struct_fields)]
#![allow(unused)]
use boa_engine::{value::TryFromJs, Context, JsNativeError, JsResult, JsValue};

2
tests/macros/tests/derive/simple_struct.rs

@ -1,4 +1,4 @@
#![allow(unused, unused_tuple_struct_fields)]
#![allow(unused)]
use boa_engine::value::TryFromJs;

2
tests/macros/tests/tests.rs

@ -1,4 +1,4 @@
#![allow(unused_crate_dependencies, unused_tuple_struct_fields)]
#![allow(unused_crate_dependencies)]
#[test]
fn try_from_js() {

3
tests/tester/src/exec/mod.rs

@ -680,8 +680,7 @@ fn is_error_type(error: &JsError, target_type: ErrorType, context: &mut Context)
.and_then(|o| o.get(js_string!("name"), context).ok())
.as_ref()
.and_then(JsValue::as_string)
.map(|s| s == target_type.as_str())
.unwrap_or_default();
.is_some_and(|s| s == target_type.as_str());
passed
}
}

3
tests/tester/src/main.rs

@ -94,8 +94,7 @@ impl Ignored {
feature
.split('.')
.next()
.map(|feat| self.features.contains(feat))
.unwrap_or_default()
.is_some_and(|feat| self.features.contains(feat))
}
pub(crate) const fn contains_any_flag(&self, flags: TestFlags) -> bool {

Loading…
Cancel
Save