From 6ac435ffea319cb772c0812d6015342261713dad Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Fri, 29 Dec 2023 06:57:09 +0100 Subject: [PATCH] Fix rust 1.75 lints (#3540) --- cli/src/debug/function.rs | 4 +- cli/src/debug/object.rs | 2 +- core/engine/src/builtins/array/mod.rs | 6 +-- core/engine/src/builtins/boolean/mod.rs | 2 +- core/engine/src/builtins/date/mod.rs | 2 +- core/engine/src/builtins/intl/collator/mod.rs | 1 + .../src/builtins/intl/date_time_format.rs | 4 +- .../iterable/async_from_sync_iterator.rs | 6 +-- core/engine/src/builtins/json/mod.rs | 2 +- core/engine/src/builtins/number/globals.rs | 8 +-- core/engine/src/builtins/number/mod.rs | 12 ++--- core/engine/src/builtins/object/mod.rs | 10 ++-- core/engine/src/builtins/reflect/mod.rs | 22 ++++---- core/engine/src/builtins/regexp/mod.rs | 2 +- core/engine/src/builtins/string/mod.rs | 2 +- core/engine/src/builtins/symbol/mod.rs | 4 +- .../src/builtins/temporal/duration/mod.rs | 2 +- .../src/builtins/typed_array/builtin.rs | 4 +- core/engine/src/builtins/weak/weak_ref.rs | 2 +- core/engine/src/module/synthetic.rs | 5 +- core/engine/src/native_function.rs | 2 +- .../engine/src/object/internal_methods/mod.rs | 2 +- core/engine/src/small_map/mod.rs | 4 ++ core/engine/src/vm/flowgraph/graph.rs | 14 ++--- core/engine/src/vm/opcode/call/mod.rs | 4 +- core/parser/src/lib.rs | 3 +- .../expression/assignment/arrow_function.rs | 52 +++++++++---------- .../assignment/async_arrow_function.rs | 48 ++++++++--------- core/runtime/src/console/mod.rs | 12 ++--- core/temporal/src/components/duration.rs | 7 +++ examples/src/bin/classes.rs | 2 +- examples/src/bin/jsarray.rs | 6 +-- examples/src/bin/jstypedarray.rs | 2 +- tests/tester/src/exec/js262.rs | 4 +- 34 files changed, 134 insertions(+), 130 deletions(-) diff --git a/cli/src/debug/function.rs b/cli/src/debug/function.rs index cb94b34b99..8337ba708b 100644 --- a/cli/src/debug/function.rs +++ b/cli/src/debug/function.rs @@ -52,7 +52,7 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult { /// Get functions instruction flowgraph fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { - let Some(value) = args.get(0) else { + let Some(value) = args.first() else { return Err(JsNativeError::typ() .with_message("expected function argument") .into()); @@ -100,7 +100,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu } fn bytecode(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult { - let Some(value) = args.get(0) else { + let Some(value) = args.first() else { return Err(JsNativeError::typ() .with_message("expected function argument") .into()); diff --git a/cli/src/debug/object.rs b/cli/src/debug/object.rs index da0db74813..c81d91be68 100644 --- a/cli/src/debug/object.rs +++ b/cli/src/debug/object.rs @@ -5,7 +5,7 @@ use boa_engine::{ /// Returns objects pointer in memory. fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult { - let Some(value) = args.get(0) else { + let Some(value) = args.first() else { return Err(JsNativeError::typ() .with_message("expected object argument") .into()); diff --git a/core/engine/src/builtins/array/mod.rs b/core/engine/src/builtins/array/mod.rs index f9f31c0aa4..5aa44e24ab 100644 --- a/core/engine/src/builtins/array/mod.rs +++ b/core/engine/src/builtins/array/mod.rs @@ -1769,7 +1769,7 @@ impl Array { let mut depth_num = 1; // 4. If depth is not undefined, then set depthNum to IntegerOrInfinity(depth) - if let Some(depth) = args.get(0) { + if let Some(depth) = args.first() { // a. Set depthNum to ? ToIntegerOrInfinity(depth). // b. If depthNum < 0, set depthNum to 0. match depth.to_integer_or_infinity(context)? { @@ -2270,7 +2270,7 @@ impl Array { // 2. Let len be ? LengthOfArrayLike(O). let len = o.length_of_array_like(context)?; - let start = args.get(0); + let start = args.first(); let delete_count = args.get(1); let items = args.get(2..).unwrap_or_default(); @@ -2410,7 +2410,7 @@ impl Array { // 2. Let len be ? LengthOfArrayLike(O). let len = o.length_of_array_like(context)?; - let start = args.get(0); + let start = args.first(); let skip_count = args.get(1); let items = args.get(2..).unwrap_or_default(); diff --git a/core/engine/src/builtins/boolean/mod.rs b/core/engine/src/builtins/boolean/mod.rs index c72e7e3aec..a393923cc8 100644 --- a/core/engine/src/builtins/boolean/mod.rs +++ b/core/engine/src/builtins/boolean/mod.rs @@ -64,7 +64,7 @@ impl BuiltInConstructor for Boolean { context: &mut Context, ) -> JsResult { // Get the argument, if any - let data = args.get(0).map_or(false, JsValue::to_boolean); + let data = args.first().map_or(false, JsValue::to_boolean); if new_target.is_undefined() { return Ok(JsValue::new(data)); } diff --git a/core/engine/src/builtins/date/mod.rs b/core/engine/src/builtins/date/mod.rs index 0727632e04..790777ab4e 100644 --- a/core/engine/src/builtins/date/mod.rs +++ b/core/engine/src/builtins/date/mod.rs @@ -448,7 +448,7 @@ impl Date { // This method is implementation-defined and discouraged, so we just require the same format as the string // constructor. - let date = some_or_nan!(args.get(0)); + let date = some_or_nan!(args.first()); let date = date.to_string(context)?; diff --git a/core/engine/src/builtins/intl/collator/mod.rs b/core/engine/src/builtins/intl/collator/mod.rs index 9ad72c59ab..2b4127a0cc 100644 --- a/core/engine/src/builtins/intl/collator/mod.rs +++ b/core/engine/src/builtins/intl/collator/mod.rs @@ -43,6 +43,7 @@ mod options; pub(crate) use options::*; #[derive(Debug, Finalize, JsData)] +#[allow(clippy::struct_field_names)] pub(crate) struct Collator { locale: Locale, collation: Value, diff --git a/core/engine/src/builtins/intl/date_time_format.rs b/core/engine/src/builtins/intl/date_time_format.rs index 0a466f08d9..01c8d84fc8 100644 --- a/core/engine/src/builtins/intl/date_time_format.rs +++ b/core/engine/src/builtins/intl/date_time_format.rs @@ -42,7 +42,7 @@ impl OptionType for HourCycle { /// JavaScript `Intl.DateTimeFormat` object. #[derive(Debug, Clone, Trace, Finalize, JsData)] pub(crate) struct DateTimeFormat { - initialized_date_time_format: bool, + initialized: bool, locale: JsString, calendar: JsString, numbering_system: JsString, @@ -125,7 +125,7 @@ impl BuiltInConstructor for DateTimeFormat { context.root_shape(), prototype, Self { - initialized_date_time_format: true, + initialized: true, locale: js_string!("en-US"), calendar: js_string!("gregory"), numbering_system: js_string!("arab"), diff --git a/core/engine/src/builtins/iterable/async_from_sync_iterator.rs b/core/engine/src/builtins/iterable/async_from_sync_iterator.rs index 94fe5fbdb5..ead34375b8 100644 --- a/core/engine/src/builtins/iterable/async_from_sync_iterator.rs +++ b/core/engine/src/builtins/iterable/async_from_sync_iterator.rs @@ -121,7 +121,7 @@ impl AsyncFromSyncIterator { let result = next .call( &iterator.into(), - args.get(0).map_or(&[], std::slice::from_ref), + args.first().map_or(&[], std::slice::from_ref), context, ) .and_then(IteratorResult::from_value); @@ -164,7 +164,7 @@ impl AsyncFromSyncIterator { // 6. IfAbruptRejectPromise(return, promiseCapability). let r#return = if_abrupt_reject_promise!(r#return, promise_capability, context); - let result = match (r#return, args.get(0)) { + let result = match (r#return, args.first()) { // 7. If return is undefined, then (None, _) => { // a. Let iterResult be CreateIterResultObject(value, true). @@ -234,7 +234,7 @@ impl AsyncFromSyncIterator { // 6. IfAbruptRejectPromise(throw, promiseCapability). let throw = if_abrupt_reject_promise!(throw, promise_capability, context); - let result = match (throw, args.get(0)) { + let result = match (throw, args.first()) { // 7. If throw is undefined, then (None, _) => { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »). diff --git a/core/engine/src/builtins/json/mod.rs b/core/engine/src/builtins/json/mod.rs index ca79b2b56c..817fecf40d 100644 --- a/core/engine/src/builtins/json/mod.rs +++ b/core/engine/src/builtins/json/mod.rs @@ -84,7 +84,7 @@ impl Json { pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let jsonString be ? ToString(text). let json_string = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_string(context)? diff --git a/core/engine/src/builtins/number/globals.rs b/core/engine/src/builtins/number/globals.rs index 7e8127228e..6ec4d0be66 100644 --- a/core/engine/src/builtins/number/globals.rs +++ b/core/engine/src/builtins/number/globals.rs @@ -26,7 +26,7 @@ use num_traits::Num; /// [spec]: https://tc39.es/ecma262/#sec-isfinite-number /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite fn is_finite(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { - if let Some(value) = args.get(0) { + if let Some(value) = args.first() { let number = value.to_number(context)?; Ok(number.is_finite().into()) } else { @@ -68,7 +68,7 @@ impl BuiltInObject for IsFinite { /// [spec]: https://tc39.es/ecma262/#sec-isnan-number /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN pub(crate) fn is_nan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { - if let Some(value) = args.get(0) { + if let Some(value) = args.first() { let number = value.to_number(context)?; Ok(number.is_nan().into()) } else { @@ -110,7 +110,7 @@ impl BuiltInObject for IsNaN { /// [spec]: https://tc39.es/ecma262/#sec-parseint-string-radix /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt pub(crate) fn parse_int(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { - if let (Some(val), radix) = (args.get(0), args.get_or_undefined(1)) { + if let (Some(val), radix) = (args.first(), args.get_or_undefined(1)) { // 1. Let inputString be ? ToString(string). let input_string = val.to_string(context)?; @@ -252,7 +252,7 @@ pub(crate) fn parse_float( args: &[JsValue], context: &mut Context, ) -> JsResult { - if let Some(val) = args.get(0) { + if let Some(val) = args.first() { // TODO: parse float with optimal utf16 algorithm let input_string = val.to_string(context)?.to_std_string_escaped(); let s = input_string.trim_start_matches(is_trimmable_whitespace); diff --git a/core/engine/src/builtins/number/mod.rs b/core/engine/src/builtins/number/mod.rs index 25e8c9560f..592f157b52 100644 --- a/core/engine/src/builtins/number/mod.rs +++ b/core/engine/src/builtins/number/mod.rs @@ -117,7 +117,7 @@ impl BuiltInConstructor for Number { args: &[JsValue], context: &mut Context, ) -> JsResult { - let data = match args.get(0) { + let data = match args.first() { Some(value) => value.to_numeric_number(context)?, None => 0.0, }; @@ -221,7 +221,7 @@ impl Number { ) -> JsResult { // 1. Let x be ? thisNumberValue(this value). let this_num = Self::this_number_value(this)?; - let precision = match args.get(0) { + let precision = match args.first() { None | Some(JsValue::Undefined) => None, // 2. Let f be ? ToIntegerOrInfinity(fractionDigits). Some(n) => Some(n.to_integer_or_infinity(context)?), @@ -748,7 +748,7 @@ impl Number { // 1. If number is not a Number, return false. // 2. If number is not finite, return false. // 3. Otherwise, return true. - Ok(JsValue::new(args.get(0).map_or(false, |val| match val { + Ok(JsValue::new(args.first().map_or(false, |val| match val { JsValue::Integer(_) => true, JsValue::Rational(number) => number.is_finite(), _ => false, @@ -771,7 +771,7 @@ impl Number { args: &[JsValue], _ctx: &mut Context, ) -> JsResult { - Ok(args.get(0).map_or(false, Self::is_integer).into()) + Ok(args.first().map_or(false, Self::is_integer).into()) } /// `Number.isNaN( number )` @@ -795,7 +795,7 @@ impl Number { _ctx: &mut Context, ) -> JsResult { Ok(JsValue::new( - if let Some(&JsValue::Rational(number)) = args.get(0) { + if let Some(&JsValue::Rational(number)) = args.first() { number.is_nan() } else { false @@ -823,7 +823,7 @@ impl Number { args: &[JsValue], _ctx: &mut Context, ) -> JsResult { - Ok(JsValue::new(match args.get(0) { + Ok(JsValue::new(match args.first() { Some(JsValue::Integer(_)) => true, Some(JsValue::Rational(number)) if Self::is_float_integer(*number) => { number.abs() <= Self::MAX_SAFE_INTEGER diff --git a/core/engine/src/builtins/object/mod.rs b/core/engine/src/builtins/object/mod.rs index a56ef71ee8..d5048ae972 100644 --- a/core/engine/src/builtins/object/mod.rs +++ b/core/engine/src/builtins/object/mod.rs @@ -676,7 +676,7 @@ impl OrdinaryObject { // 1. Set O to ? RequireObjectCoercible(O). let o = args - .get(0) + .first() .cloned() .unwrap_or_default() .require_object_coercible()? @@ -945,7 +945,7 @@ impl OrdinaryObject { args: &[JsValue], context: &mut Context, ) -> JsResult { - let Some(key) = args.get(0) else { + let Some(key) = args.first() else { return Ok(JsValue::new(false)); }; @@ -1030,7 +1030,7 @@ impl OrdinaryObject { pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let obj be ? ToObject(target). let obj = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_object(context)?; @@ -1055,7 +1055,7 @@ impl OrdinaryObject { pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let obj be ? ToObject(target). let obj = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_object(context)?; @@ -1084,7 +1084,7 @@ impl OrdinaryObject { pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let obj be ? ToObject(target). let obj = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_object(context)?; diff --git a/core/engine/src/builtins/reflect/mod.rs b/core/engine/src/builtins/reflect/mod.rs index eebf558b43..f4d405adf7 100644 --- a/core/engine/src/builtins/reflect/mod.rs +++ b/core/engine/src/builtins/reflect/mod.rs @@ -84,7 +84,7 @@ impl Reflect { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply pub(crate) fn apply(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be a function"))?; let this_arg = args.get_or_undefined(1); @@ -153,7 +153,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; let key = args.get_or_undefined(1).to_property_key(context)?; @@ -188,7 +188,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; let key = args.get_or_undefined(1).to_property_key(context)?; @@ -209,7 +209,7 @@ impl Reflect { pub(crate) fn get(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. If Type(target) is not Object, throw a TypeError exception. let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; // 2. Let key be ? ToPropertyKey(propertyKey). @@ -267,7 +267,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; Ok(target @@ -285,7 +285,7 @@ impl Reflect { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has pub(crate) fn has(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; let key = args @@ -312,7 +312,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; Ok(target @@ -334,7 +334,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; @@ -361,7 +361,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; @@ -380,7 +380,7 @@ impl Reflect { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set pub(crate) fn set(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; let key = args.get_or_undefined(1).to_property_key(context)?; @@ -414,7 +414,7 @@ impl Reflect { context: &mut Context, ) -> JsResult { let target = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?; let proto = match args.get_or_undefined(1) { diff --git a/core/engine/src/builtins/regexp/mod.rs b/core/engine/src/builtins/regexp/mod.rs index eb7c62cdb2..357af1bd52 100644 --- a/core/engine/src/builtins/regexp/mod.rs +++ b/core/engine/src/builtins/regexp/mod.rs @@ -760,7 +760,7 @@ impl RegExp { // 3. Let string be ? ToString(S). let arg_str = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_string(context)?; diff --git a/core/engine/src/builtins/string/mod.rs b/core/engine/src/builtins/string/mod.rs index ec888839be..07a6cf7e52 100644 --- a/core/engine/src/builtins/string/mod.rs +++ b/core/engine/src/builtins/string/mod.rs @@ -209,7 +209,7 @@ impl BuiltInConstructor for String { ) -> JsResult { // This value is used by console.log and other routines to match Object type // to its Javascript Identifier (global constructor method name) - let string = match args.get(0) { + let string = match args.first() { // 2. Else, // a. If NewTarget is undefined and Type(value) is Symbol, return SymbolDescriptiveString(value). Some(JsValue::Symbol(ref sym)) if new_target.is_undefined() => { diff --git a/core/engine/src/builtins/symbol/mod.rs b/core/engine/src/builtins/symbol/mod.rs index 680d79c647..0efe1080c8 100644 --- a/core/engine/src/builtins/symbol/mod.rs +++ b/core/engine/src/builtins/symbol/mod.rs @@ -213,7 +213,7 @@ impl BuiltInConstructor for Symbol { // 2. If description is undefined, let descString be undefined. // 3. Else, let descString be ? ToString(description). - let description = match args.get(0) { + let description = match args.first() { Some(value) if !value.is_undefined() => Some(value.to_string(context)?), _ => None, }; @@ -315,7 +315,7 @@ impl Symbol { pub(crate) fn for_(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let stringKey be ? ToString(key). let string_key = args - .get(0) + .first() .cloned() .unwrap_or_default() .to_string(context)?; diff --git a/core/engine/src/builtins/temporal/duration/mod.rs b/core/engine/src/builtins/temporal/duration/mod.rs index f03a7d914b..dd4b986ce9 100644 --- a/core/engine/src/builtins/temporal/duration/mod.rs +++ b/core/engine/src/builtins/temporal/duration/mod.rs @@ -186,7 +186,7 @@ impl BuiltInConstructor for Duration { // 2. If years is undefined, let y be 0; else let y be ? ToIntegerIfIntegral(years). let years = f64::from( - args.get(0) + args.first() .map_or(Ok(0), |y| to_integer_if_integral(y, context))?, ); diff --git a/core/engine/src/builtins/typed_array/builtin.rs b/core/engine/src/builtins/typed_array/builtin.rs index 17085583af..078393f1e6 100644 --- a/core/engine/src/builtins/typed_array/builtin.rs +++ b/core/engine/src/builtins/typed_array/builtin.rs @@ -2510,7 +2510,7 @@ impl BuiltinTypedArray { context: &mut Context, ) -> JsResult { // 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. - let compare_fn = match args.get(0) { + let compare_fn = match args.first() { None | Some(JsValue::Undefined) => None, Some(JsValue::Object(obj)) if obj.is_callable() => Some(obj), _ => { @@ -2577,7 +2577,7 @@ impl BuiltinTypedArray { context: &mut Context, ) -> JsResult { // 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. - let compare_fn = match args.get(0) { + let compare_fn = match args.first() { None | Some(JsValue::Undefined) => None, Some(JsValue::Object(obj)) if obj.is_callable() => Some(obj), _ => { diff --git a/core/engine/src/builtins/weak/weak_ref.rs b/core/engine/src/builtins/weak/weak_ref.rs index de4a9e0d86..8442e6ac1b 100644 --- a/core/engine/src/builtins/weak/weak_ref.rs +++ b/core/engine/src/builtins/weak/weak_ref.rs @@ -73,7 +73,7 @@ impl BuiltInConstructor for WeakRef { } // 2. If target is not an Object, throw a TypeError exception. - let target = args.get(0).and_then(JsValue::as_object).ok_or_else(|| { + let target = args.first().and_then(JsValue::as_object).ok_or_else(|| { JsNativeError::typ().with_message(format!( "WeakRef: expected target argument of type `object`, got target of type `{}`", args.get_or_undefined(0).type_of() diff --git a/core/engine/src/module/synthetic.rs b/core/engine/src/module/synthetic.rs index a7e47a9e4b..2b993131dc 100644 --- a/core/engine/src/module/synthetic.rs +++ b/core/engine/src/module/synthetic.rs @@ -97,7 +97,10 @@ impl SyntheticModuleInitializer { { // SAFETY: The caller must ensure the invariants of the closure hold. unsafe { - Self::from_closure_with_captures(move |module, _, context| closure(module, context), ()) + Self::from_closure_with_captures( + move |module, (), context| closure(module, context), + (), + ) } } diff --git a/core/engine/src/native_function.rs b/core/engine/src/native_function.rs index 1a98631756..721f53291f 100644 --- a/core/engine/src/native_function.rs +++ b/core/engine/src/native_function.rs @@ -275,7 +275,7 @@ impl NativeFunction { // SAFETY: The caller must ensure the invariants of the closure hold. unsafe { Self::from_closure_with_captures( - move |this, args, _, context| closure(this, args, context), + move |this, args, (), context| closure(this, args, context), (), ) } diff --git a/core/engine/src/object/internal_methods/mod.rs b/core/engine/src/object/internal_methods/mod.rs index 8fb32e0d73..bb37c9ca8a 100644 --- a/core/engine/src/object/internal_methods/mod.rs +++ b/core/engine/src/object/internal_methods/mod.rs @@ -324,7 +324,7 @@ pub(crate) static ORDINARY_INTERNAL_METHODS: InternalObjectMethods = InternalObj /// /// For a guide on how to implement exotic internal methods, see `ORDINARY_INTERNAL_METHODS`. #[derive(Debug, Clone, Copy)] -#[allow(clippy::type_complexity)] +#[allow(clippy::type_complexity, clippy::struct_field_names)] pub struct InternalObjectMethods { pub(crate) __get_prototype_of__: fn(&JsObject, &mut Context) -> JsResult, pub(crate) __set_prototype_of__: fn(&JsObject, JsPrototype, &mut Context) -> JsResult, diff --git a/core/engine/src/small_map/mod.rs b/core/engine/src/small_map/mod.rs index 7a8687718f..627b71eee3 100644 --- a/core/engine/src/small_map/mod.rs +++ b/core/engine/src/small_map/mod.rs @@ -173,6 +173,7 @@ impl SmallMap { /// /// The supplied key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. + #[allow(clippy::map_identity)] pub fn get_key_value(&self, key: &Q) -> Option<(&K, &V)> where K: Borrow + Ord + Eq, @@ -371,6 +372,7 @@ impl<'a, K, V, const ARRAY_SIZE: usize> IntoIterator for &'a SmallMap Iterator for Iter<'a, K, V> { type Item = (&'a K, &'a V); + #[allow(clippy::map_identity)] fn next(&mut self) -> Option { match &mut self.inner { InnerIter::Inline(i) => i.next().map(|(k, v)| (k, v)), @@ -385,6 +387,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> { } } + #[allow(clippy::map_identity)] fn last(self) -> Option<(&'a K, &'a V)> { match self.inner { InnerIter::Inline(i) => i.last().map(|(k, v)| (k, v)), @@ -396,6 +399,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> { impl FusedIterator for Iter<'_, K, V> {} impl<'a, K: 'a, V: 'a> DoubleEndedIterator for Iter<'a, K, V> { + #[allow(clippy::map_identity)] fn next_back(&mut self) -> Option<(&'a K, &'a V)> { match &mut self.inner { InnerIter::Inline(i) => i.next_back().map(|(k, v)| (k, v)), diff --git a/core/engine/src/vm/flowgraph/graph.rs b/core/engine/src/vm/flowgraph/graph.rs index e82eba9fcf..6092ef5a99 100644 --- a/core/engine/src/vm/flowgraph/graph.rs +++ b/core/engine/src/vm/flowgraph/graph.rs @@ -1,9 +1,5 @@ -use std::{ - collections::hash_map::RandomState, - hash::{BuildHasher, Hash, Hasher}, -}; - use crate::vm::flowgraph::{Color, Edge, EdgeStyle, EdgeType, Node, NodeShape}; +use std::{collections::hash_map::RandomState, hash::BuildHasher}; /// This represents the direction of flow in the flowgraph. #[derive(Debug, Clone, Copy)] @@ -100,9 +96,7 @@ impl SubGraph { /// Format into the graphviz format. fn graphviz_format(&self, result: &mut String, prefix: &str) { - let mut hasher = RandomState::new().build_hasher(); - self.label.hash(&mut hasher); - let label = format!("{}", hasher.finish()); + let label = format!("{}", RandomState::new().hash_one(&self.label)); result.push_str(&format!("\tsubgraph cluster_{prefix}_{label} {{\n")); result.push_str("\t\tstyle = filled;\n"); result.push_str(&format!( @@ -164,9 +158,7 @@ impl SubGraph { /// Format into the mermaid format. fn mermaid_format(&self, result: &mut String, prefix: &str) { - let mut hasher = RandomState::new().build_hasher(); - self.label.hash(&mut hasher); - let label = format!("{}", hasher.finish()); + let label = format!("{}", RandomState::new().hash_one(&self.label)); let rankdir = match self.direction { Direction::TopToBottom => "TB", Direction::BottomToTop => "BT", diff --git a/core/engine/src/vm/opcode/call/mod.rs b/core/engine/src/vm/opcode/call/mod.rs index 500bb46721..2e357952f9 100644 --- a/core/engine/src/vm/opcode/call/mod.rs +++ b/core/engine/src/vm/opcode/call/mod.rs @@ -37,7 +37,7 @@ impl CallEval { let arguments = context.vm.pop_n_values(argument_count); let _func = context.vm.pop(); let _this = context.vm.pop(); - if let Some(x) = arguments.get(0) { + if let Some(x) = arguments.first() { // i. Let argList be ? ArgumentListEvaluation of arguments. // ii. If argList has no elements, return undefined. // iii. Let evalArg be the first element of argList. @@ -130,7 +130,7 @@ impl Operation for CallEvalSpread { if JsObject::equals(object, &eval) { let _func = context.vm.pop(); let _this = context.vm.pop(); - if let Some(x) = arguments.get(0) { + if let Some(x) = arguments.first() { // i. Let argList be ? ArgumentListEvaluation of arguments. // ii. If argList has no elements, return undefined. // iii. Let evalArg be the first element of argList. diff --git a/core/parser/src/lib.rs b/core/parser/src/lib.rs index 3649d4a2e9..23203c22c3 100644 --- a/core/parser/src/lib.rs +++ b/core/parser/src/lib.rs @@ -21,7 +21,8 @@ clippy::too_many_lines, clippy::cognitive_complexity, clippy::let_unit_value, - clippy::redundant_pub_crate + clippy::redundant_pub_crate, + clippy::struct_field_names )] pub mod error; diff --git a/core/parser/src/parser/expression/assignment/arrow_function.rs b/core/parser/src/parser/expression/assignment/arrow_function.rs index cd4d788bc1..8066046473 100644 --- a/core/parser/src/parser/expression/assignment/arrow_function.rs +++ b/core/parser/src/parser/expression/assignment/arrow_function.rs @@ -81,33 +81,31 @@ where let _timer = Profiler::global().start_event("ArrowFunction", "Parsing"); let next_token = cursor.peek(0, interner).or_abrupt()?; - let (params, params_start_position) = if next_token.kind() - == &TokenKind::Punctuator(Punctuator::OpenParen) - { - // CoverParenthesizedExpressionAndArrowParameterList - let params_start_position = cursor - .expect(Punctuator::OpenParen, "arrow function", interner)? - .span() - .end(); - - let params = FormalParameters::new(self.allow_yield, self.allow_await) - .parse(cursor, interner)?; - cursor.expect(Punctuator::CloseParen, "arrow function", interner)?; - (params, params_start_position) - } else { - let params_start_position = next_token.span().start(); - let param = BindingIdentifier::new(self.allow_yield, self.allow_await) - .parse(cursor, interner) - .set_context("arrow function")?; - ( - FormalParameterList::try_from(FormalParameter::new( - Variable::from_identifier(param, None), - false, - )) - .expect("a single binding identifier without init is always a valid param list"), - params_start_position, - ) - }; + let (params, params_start_position) = + if next_token.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) { + // CoverParenthesizedExpressionAndArrowParameterList + let params_start_position = cursor + .expect(Punctuator::OpenParen, "arrow function", interner)? + .span() + .end(); + + let params = FormalParameters::new(self.allow_yield, self.allow_await) + .parse(cursor, interner)?; + cursor.expect(Punctuator::CloseParen, "arrow function", interner)?; + (params, params_start_position) + } else { + let params_start_position = next_token.span().start(); + let param = BindingIdentifier::new(self.allow_yield, self.allow_await) + .parse(cursor, interner) + .set_context("arrow function")?; + ( + FormalParameterList::from(FormalParameter::new( + Variable::from_identifier(param, None), + false, + )), + params_start_position, + ) + }; cursor.peek_expect_no_lineterminator(0, "arrow function", interner)?; diff --git a/core/parser/src/parser/expression/assignment/async_arrow_function.rs b/core/parser/src/parser/expression/assignment/async_arrow_function.rs index 62deaa9d7e..3c3ed7cba9 100644 --- a/core/parser/src/parser/expression/assignment/async_arrow_function.rs +++ b/core/parser/src/parser/expression/assignment/async_arrow_function.rs @@ -77,31 +77,29 @@ where cursor.peek_expect_no_lineterminator(0, "async arrow function", interner)?; let next_token = cursor.peek(0, interner).or_abrupt()?; - let (params, params_start_position) = if next_token.kind() - == &TokenKind::Punctuator(Punctuator::OpenParen) - { - let params_start_position = cursor - .expect(Punctuator::OpenParen, "async arrow function", interner)? - .span() - .end(); - - let params = FormalParameters::new(false, true).parse(cursor, interner)?; - cursor.expect(Punctuator::CloseParen, "async arrow function", interner)?; - (params, params_start_position) - } else { - let params_start_position = next_token.span().start(); - let param = BindingIdentifier::new(self.allow_yield, true) - .parse(cursor, interner) - .set_context("async arrow function")?; - ( - FormalParameterList::try_from(FormalParameter::new( - Variable::from_identifier(param, None), - false, - )) - .expect("a single binding identifier without init is always a valid param list"), - params_start_position, - ) - }; + let (params, params_start_position) = + if next_token.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) { + let params_start_position = cursor + .expect(Punctuator::OpenParen, "async arrow function", interner)? + .span() + .end(); + + let params = FormalParameters::new(false, true).parse(cursor, interner)?; + cursor.expect(Punctuator::CloseParen, "async arrow function", interner)?; + (params, params_start_position) + } else { + let params_start_position = next_token.span().start(); + let param = BindingIdentifier::new(self.allow_yield, true) + .parse(cursor, interner) + .set_context("async arrow function")?; + ( + FormalParameterList::from(FormalParameter::new( + Variable::from_identifier(param, None), + false, + )), + params_start_position, + ) + }; cursor.peek_expect_no_lineterminator(0, "async arrow function", interner)?; cursor.expect(Punctuator::Arrow, "async arrow function", interner)?; diff --git a/core/runtime/src/console/mod.rs b/core/runtime/src/console/mod.rs index 26b20a2735..df89049687 100644 --- a/core/runtime/src/console/mod.rs +++ b/core/runtime/src/console/mod.rs @@ -270,7 +270,7 @@ impl Console { console: &Self, context: &mut Context, ) -> JsResult { - let assertion = args.get(0).map_or(false, JsValue::to_boolean); + let assertion = args.first().map_or(false, JsValue::to_boolean); if !assertion { let mut args: Vec = args.iter().skip(1).cloned().collect(); @@ -456,7 +456,7 @@ impl Console { console: &mut Self, context: &mut Context, ) -> JsResult { - let label = match args.get(0) { + let label = match args.first() { Some(value) => value.to_string(context)?, None => "default".into(), }; @@ -485,7 +485,7 @@ impl Console { console: &mut Self, context: &mut Context, ) -> JsResult { - let label = match args.get(0) { + let label = match args.first() { Some(value) => value.to_string(context)?, None => "default".into(), }; @@ -524,7 +524,7 @@ impl Console { console: &mut Self, context: &mut Context, ) -> JsResult { - let label = match args.get(0) { + let label = match args.first() { Some(value) => value.to_string(context)?, None => "default".into(), }; @@ -561,7 +561,7 @@ impl Console { console: &Self, context: &mut Context, ) -> JsResult { - let label = match args.get(0) { + let label = match args.first() { Some(value) => value.to_string(context)?, None => "default".into(), }; @@ -605,7 +605,7 @@ impl Console { console: &mut Self, context: &mut Context, ) -> JsResult { - let label = match args.get(0) { + let label = match args.first() { Some(value) => value.to_string(context)?, None => "default".into(), }; diff --git a/core/temporal/src/components/duration.rs b/core/temporal/src/components/duration.rs index 2f8198d2a3..e797e5b911 100644 --- a/core/temporal/src/components/duration.rs +++ b/core/temporal/src/components/duration.rs @@ -361,6 +361,13 @@ impl Duration { pub fn is_time_within_range(&self) -> bool { self.time.is_within_range() } + + /// Return an iterator over the `Duration`'s values. + #[inline] + #[must_use] + pub fn iter(&self) -> DurationIter<'_> { + <&Self as IntoIterator>::into_iter(self) + } } // ==== Public `Duration` Getters/Setters ==== diff --git a/examples/src/bin/classes.rs b/examples/src/bin/classes.rs index 15e6a248d2..943a27410c 100644 --- a/examples/src/bin/classes.rs +++ b/examples/src/bin/classes.rs @@ -107,7 +107,7 @@ impl Class for Person { js_string!("is"), 1, NativeFunction::from_fn_ptr(|_this, args, _ctx| { - if let Some(arg) = args.get(0) { + if let Some(arg) = args.first() { if let Some(object) = arg.as_object() { // We check if the type of `args[0]` is `Person` if object.is::() { diff --git a/examples/src/bin/jsarray.rs b/examples/src/bin/jsarray.rs index a750f16f06..c870831bb0 100644 --- a/examples/src/bin/jsarray.rs +++ b/examples/src/bin/jsarray.rs @@ -68,7 +68,7 @@ fn main() -> JsResult<()> { let filter_callback = FunctionObjectBuilder::new( context.realm(), NativeFunction::from_fn_ptr(|_this, args, _context| { - Ok(args.get(0).cloned().unwrap_or_default().is_number().into()) + Ok(args.first().cloned().unwrap_or_default().is_number().into()) }), ) .build(); @@ -76,7 +76,7 @@ fn main() -> JsResult<()> { let map_callback = FunctionObjectBuilder::new( context.realm(), NativeFunction::from_fn_ptr(|_this, args, context| { - args.get(0) + args.first() .cloned() .unwrap_or_default() .pow(&JsValue::new(2), context) @@ -102,7 +102,7 @@ fn main() -> JsResult<()> { let reduce_callback = FunctionObjectBuilder::new( context.realm(), NativeFunction::from_fn_ptr(|_this, args, context| { - let accumulator = args.get(0).cloned().unwrap_or_default(); + let accumulator = args.first().cloned().unwrap_or_default(); let value = args.get(1).cloned().unwrap_or_default(); accumulator.add(&value, context) diff --git a/examples/src/bin/jstypedarray.rs b/examples/src/bin/jstypedarray.rs index fed57da639..d5fdf5915a 100644 --- a/examples/src/bin/jstypedarray.rs +++ b/examples/src/bin/jstypedarray.rs @@ -28,7 +28,7 @@ fn main() -> JsResult<()> { let callback = FunctionObjectBuilder::new( context.realm(), NativeFunction::from_fn_ptr(|_this, args, context| { - let accumulator = args.get(0).cloned().unwrap_or_default(); + let accumulator = args.first().cloned().unwrap_or_default(); let value = args.get(1).cloned().unwrap_or_default(); accumulator.add(&value, context) diff --git a/tests/tester/src/exec/js262.rs b/tests/tester/src/exec/js262.rs index 2c51627d87..350d5b51e4 100644 --- a/tests/tester/src/exec/js262.rs +++ b/tests/tester/src/exec/js262.rs @@ -136,7 +136,7 @@ fn detach_array_buffer(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResu } let array_buffer = args - .get(0) + .first() .and_then(JsValue::as_object) .ok_or_else(type_err)?; let mut array_buffer = array_buffer.borrow_mut(); @@ -162,7 +162,7 @@ fn detach_array_buffer(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResu /// /// Accepts a string value as its first argument and executes it as an ECMAScript script. fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { - args.get(0).and_then(JsValue::as_string).map_or_else( + args.first().and_then(JsValue::as_string).map_or_else( || Ok(JsValue::undefined()), |source_text| context.eval(Source::from_bytes(&source_text.to_std_string_escaped())), )