From 03d972957d09a22364ea9f206112fddc07b5fcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Fri, 22 Mar 2024 01:54:54 +0000 Subject: [PATCH] Apply new clippy lints for rustc 1.77 (#3759) * First bump fixes * Apply automatic clippy lints * cargo fmt * Apply manual lints --- Cargo.toml | 1 - cli/src/main.rs | 1 + core/engine/src/builtins/array_buffer/mod.rs | 3 +-- core/engine/src/builtins/number/globals.rs | 2 +- .../src/builtins/typed_array/element/mod.rs | 1 - .../engine/src/builtins/typed_array/object.rs | 9 +++------ core/engine/src/context/mod.rs | 2 +- core/engine/src/module/source.rs | 2 +- .../engine/src/object/internal_methods/mod.rs | 2 +- .../shape/shared_shape/forward_transition.rs | 8 ++------ core/engine/src/string/mod.rs | 20 +++++++++---------- core/gc/src/lib.rs | 2 +- examples/Cargo.toml | 1 - tests/macros/tests/derive/from_js_with.rs | 2 +- tests/macros/tests/derive/simple_struct.rs | 2 +- tests/macros/tests/tests.rs | 2 +- tests/tester/src/exec/mod.rs | 3 +-- tests/tester/src/main.rs | 3 +-- 18 files changed, 27 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a760e1ee8..436dd59229 100644 --- a/Cargo.toml +++ b/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] diff --git a/cli/src/main.rs b/cli/src/main.rs index f0702f7967..7408901598 100644 --- a/cli/src/main.rs +++ b/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, diff --git a/core/engine/src/builtins/array_buffer/mod.rs b/core/engine/src/builtins/array_buffer/mod.rs index b57ecd694c..1145c26f82 100644 --- a/core/engine/src/builtins/array_buffer/mod.rs +++ b/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::() || obj.is::()) - .unwrap_or_default() + .is_some_and(|obj| obj.is::() || obj.is::()) .into()) } diff --git a/core/engine/src/builtins/number/globals.rs b/core/engine/src/builtins/number/globals.rs index 6ec4d0be66..46c16a9323 100644 --- a/core/engine/src/builtins/number/globals.rs +++ b/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. diff --git a/core/engine/src/builtins/typed_array/element/mod.rs b/core/engine/src/builtins/typed_array/element/mod.rs index 51e570ea73..e3fe61d555 100644 --- a/core/engine/src/builtins/typed_array/element/mod.rs +++ b/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; diff --git a/core/engine/src/builtins/typed_array/object.rs b/core/engine/src/builtins/typed_array/object.rs index 078698a353..bb32aa6e05 100644 --- a/core/engine/src/builtins/typed_array/object.rs +++ b/core/engine/src/builtins/typed_array/object.rs @@ -579,12 +579,9 @@ fn typed_array_get_element(obj: &JsObject, index: f64) -> Option { 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(); diff --git a/core/engine/src/context/mod.rs b/core/engine/src/context/mod.rs index 727349a414..453e3891f6 100644 --- a/core/engine/src/context/mod.rs +++ b/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 = Cell::new(0); + static CANNOT_BLOCK_COUNTER: Cell = const { Cell::new(0) }; } /// ECMAScript context. It is the primary way to interact with the runtime. diff --git a/core/engine/src/module/source.rs b/core/engine/src/module/source.rs index 263962ffd7..c36b11966a 100644 --- a/core/engine/src/module/source.rs +++ b/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 { thread_local! { - static ASYNC_EVAL_QUEUE_INDEX: Cell = Cell::new(0); + static ASYNC_EVAL_QUEUE_INDEX: Cell = const { Cell::new(0) }; } ASYNC_EVAL_QUEUE_INDEX diff --git a/core/engine/src/object/internal_methods/mod.rs b/core/engine/src/object/internal_methods/mod.rs index 1d76ee9d9c..4e1efa7582 100644 --- a/core/engine/src/object/internal_methods/mod.rs +++ b/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`. diff --git a/core/engine/src/object/shape/shared_shape/forward_transition.rs b/core/engine/src/object/shape/shared_shape/forward_transition.rs index b23b0bf320..ccaf53995d 100644 --- a/core/engine/src/object/shape/shared_shape/forward_transition.rs +++ b/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> { 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> { 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() } diff --git a/core/engine/src/string/mod.rs b/core/engine/src/string/mod.rs index 425f4d1449..ccbbebed2d 100644 --- a/core/engine/src/string/mod.rs +++ b/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 { &[] diff --git a/core/gc/src/lib.rs b/core/gc/src/lib.rs index 083475ce4c..5ed1e44f6d 100644 --- a/core/gc/src/lib.rs +++ b/core/gc/src/lib.rs @@ -42,7 +42,7 @@ type GcErasedPointer = NonNull>; type EphemeronPointer = NonNull; type ErasedWeakMapBoxPointer = NonNull; -thread_local!(static GC_DROPPING: Cell = Cell::new(false)); +thread_local!(static GC_DROPPING: Cell = const { Cell::new(false) }); thread_local!(static BOA_GC: RefCell = RefCell::new( BoaGc { config: GcConfig::default(), runtime: GcRuntimeData::default(), diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 7653b3b751..4bfe6cee05 100644 --- a/examples/Cargo.toml +++ b/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] diff --git a/tests/macros/tests/derive/from_js_with.rs b/tests/macros/tests/derive/from_js_with.rs index 2fd5184d27..e7137e7e92 100644 --- a/tests/macros/tests/derive/from_js_with.rs +++ b/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}; diff --git a/tests/macros/tests/derive/simple_struct.rs b/tests/macros/tests/derive/simple_struct.rs index 5249412bb6..21ad774e39 100644 --- a/tests/macros/tests/derive/simple_struct.rs +++ b/tests/macros/tests/derive/simple_struct.rs @@ -1,4 +1,4 @@ -#![allow(unused, unused_tuple_struct_fields)] +#![allow(unused)] use boa_engine::value::TryFromJs; diff --git a/tests/macros/tests/tests.rs b/tests/macros/tests/tests.rs index d94f31d8b6..1cef0d9077 100644 --- a/tests/macros/tests/tests.rs +++ b/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() { diff --git a/tests/tester/src/exec/mod.rs b/tests/tester/src/exec/mod.rs index f57d55aff8..859e8a8d72 100644 --- a/tests/tester/src/exec/mod.rs +++ b/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 } } diff --git a/tests/tester/src/main.rs b/tests/tester/src/main.rs index 649f47837f..79999829cd 100644 --- a/tests/tester/src/main.rs +++ b/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 {