diff --git a/core/engine/src/builtins/temporal/instant/mod.rs b/core/engine/src/builtins/temporal/instant/mod.rs index 2b7173b4018..161ca0ce03b 100644 --- a/core/engine/src/builtins/temporal/instant/mod.rs +++ b/core/engine/src/builtins/temporal/instant/mod.rs @@ -153,7 +153,6 @@ impl Instant { None, context, ) - .map(Into::into) } pub(crate) fn from_epoch_milliseconds( @@ -172,7 +171,6 @@ impl Instant { None, context, ) - .map(Into::into) } pub(crate) fn from_epoch_nanoseconds( @@ -190,7 +188,6 @@ impl Instant { None, context, ) - .map(Into::into) } pub(crate) fn compare( diff --git a/core/engine/src/builtins/temporal/now.rs b/core/engine/src/builtins/temporal/now.rs index 9fbc1bf851f..5e9aaba373e 100644 --- a/core/engine/src/builtins/temporal/now.rs +++ b/core/engine/src/builtins/temporal/now.rs @@ -70,7 +70,7 @@ impl Now { /// 2.2.2 `Temporal.Now.instant()` fn instant(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { let epoch_nanos = system_nanoseconds(context)?; - create_temporal_instant(Instant::from(epoch_nanos), None, context).map(Into::into) + create_temporal_instant(Instant::from(epoch_nanos), None, context) } /// 2.2.3 `Temporal.Now.plainDateTimeISO ( [ temporalTimeZoneLike ] )` diff --git a/core/engine/src/builtins/temporal/plain_date_time/mod.rs b/core/engine/src/builtins/temporal/plain_date_time/mod.rs index c254e4699c8..e893ee32fd5 100644 --- a/core/engine/src/builtins/temporal/plain_date_time/mod.rs +++ b/core/engine/src/builtins/temporal/plain_date_time/mod.rs @@ -1218,8 +1218,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; // TODO: `temporal_rs` needs a `has_era` method let (era, era_year) = if calendar == Calendar::default() { (None, None) @@ -1254,8 +1253,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let millisecond = partial_object .get(js_string!("millisecond"), context)? @@ -1263,8 +1261,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let minute = partial_object .get(js_string!("minute"), context)? @@ -1272,8 +1269,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let month = partial_object .get(js_string!("month"), context)? @@ -1305,8 +1301,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let second = partial_object .get(js_string!("second"), context)? @@ -1314,8 +1309,7 @@ fn to_partial_datetime( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let year = partial_object .get(js_string!("year"), context)? diff --git a/core/engine/src/builtins/temporal/plain_time/mod.rs b/core/engine/src/builtins/temporal/plain_time/mod.rs index 6af1e9bbf45..cec8efd8787 100644 --- a/core/engine/src/builtins/temporal/plain_time/mod.rs +++ b/core/engine/src/builtins/temporal/plain_time/mod.rs @@ -722,8 +722,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let microsecond = partial_object .get(js_string!("microsecond"), context)? @@ -731,8 +730,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let millisecond = partial_object .get(js_string!("millisecond"), context)? @@ -740,8 +738,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let minute = partial_object .get(js_string!("minute"), context)? @@ -749,8 +746,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let nanosecond = partial_object .get(js_string!("nanosecond"), context)? @@ -758,8 +754,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; let second = partial_object .get(js_string!("second"), context)? @@ -767,8 +762,7 @@ pub(crate) fn to_partial_time_record( let finite = v.to_finitef64(context)?; Ok::(finite.as_integer_with_truncation::()) }) - .transpose()? - .map(Into::into); + .transpose()?; Ok(PartialTime { hour, diff --git a/core/engine/src/builtins/temporal/plain_year_month/mod.rs b/core/engine/src/builtins/temporal/plain_year_month/mod.rs index a44ded219e2..a530f214efe 100644 --- a/core/engine/src/builtins/temporal/plain_year_month/mod.rs +++ b/core/engine/src/builtins/temporal/plain_year_month/mod.rs @@ -214,13 +214,8 @@ impl BuiltInConstructor for PlainYearMonth { .transpose()?; // 7. Return ? CreateTemporalYearMonth(y, m, calendar, ref, NewTarget). - let inner = InnerYearMonth::new_with_overflow( - y, - m, - ref_day.map(Into::into), - calendar, - ArithmeticOverflow::Reject, - )?; + let inner = + InnerYearMonth::new_with_overflow(y, m, ref_day, calendar, ArithmeticOverflow::Reject)?; create_temporal_year_month(inner, Some(new_target), context) } diff --git a/core/engine/src/builtins/temporal/zoneddatetime/mod.rs b/core/engine/src/builtins/temporal/zoneddatetime/mod.rs index a52e020f199..81ccdac735a 100644 --- a/core/engine/src/builtins/temporal/zoneddatetime/mod.rs +++ b/core/engine/src/builtins/temporal/zoneddatetime/mod.rs @@ -1133,7 +1133,7 @@ impl ZonedDateTime { JsNativeError::typ().with_message("the this object must be a ZonedDateTime object.") })?; - create_temporal_instant(zdt.inner.to_instant(), None, context).map(Into::into) + create_temporal_instant(zdt.inner.to_instant(), None, context) } /// 6.3.48 `Temporal.ZonedDateTime.prototype.toPlainDate ( )` diff --git a/core/engine/src/error.rs b/core/engine/src/error.rs index c3f64d783e2..f8f7337af1d 100644 --- a/core/engine/src/error.rs +++ b/core/engine/src/error.rs @@ -619,7 +619,7 @@ impl JsError { /// Is the [`JsError`] catchable in JavaScript. #[inline] pub(crate) fn is_catchable(&self) -> bool { - self.as_native().map_or(true, JsNativeError::is_catchable) + self.as_native().is_none_or(JsNativeError::is_catchable) } } diff --git a/core/engine/src/module/namespace.rs b/core/engine/src/module/namespace.rs index 196e0dd0842..b0629b41eaa 100644 --- a/core/engine/src/module/namespace.rs +++ b/core/engine/src/module/namespace.rs @@ -213,7 +213,7 @@ fn module_namespace_exotic_define_own_property( // 8. If Desc has a [[Value]] field, return SameValue(Desc.[[Value]], current.[[Value]]). // 9. Return true. - Ok(desc.value().map_or(true, |v| v == current.expect_value())) + Ok(desc.value().is_none_or(|v| v == current.expect_value())) } /// [`[[HasProperty]] ( P )`][spec] diff --git a/core/engine/src/object/jsobject.rs b/core/engine/src/object/jsobject.rs index db02acd3c37..a660dbe12be 100644 --- a/core/engine/src/object/jsobject.rs +++ b/core/engine/src/object/jsobject.rs @@ -1,6 +1,10 @@ //! This module implements the `JsObject` structure. //! //! The `JsObject` is a garbage collected Object. +#![allow( + unknown_lints, + reason = "unpredictable_function_pointer_comparisons doesn't exist on 1.84" +)] use super::{ internal_methods::{InternalMethodContext, InternalObjectMethods, ORDINARY_INTERNAL_METHODS}, @@ -408,7 +412,7 @@ impl JsObject { let get = if let Some(getter) = self.try_get(js_string!("get"), context)? { // b. If IsCallable(getter) is false and getter is not undefined, throw a TypeError exception. // todo: extract IsCallable to be callable from Value - if !getter.is_undefined() && getter.as_object().map_or(true, |o| !o.is_callable()) { + if !getter.is_undefined() && getter.as_object().is_none_or(|o| !o.is_callable()) { return Err(JsNativeError::typ() .with_message("Property descriptor getter must be callable") .into()); @@ -425,7 +429,7 @@ impl JsObject { let set = if let Some(setter) = self.try_get(js_string!("set"), context)? { // 14.b. If IsCallable(setter) is false and setter is not undefined, throw a TypeError exception. // todo: extract IsCallable to be callable from Value - if !setter.is_undefined() && setter.as_object().map_or(true, |o| !o.is_callable()) { + if !setter.is_undefined() && setter.as_object().is_none_or(|o| !o.is_callable()) { return Err(JsNativeError::typ() .with_message("Property descriptor setter must be callable") .into()); @@ -748,6 +752,10 @@ impl JsObject { /// [spec]: https://tc39.es/ecma262/#sec-iscallable #[inline] #[must_use] + #[expect( + unpredictable_function_pointer_comparisons, + reason = "can only use `ptr::fn_addr_eq` on rustc 1.85" + )] pub fn is_callable(&self) -> bool { self.inner.vtable.__call__ != ORDINARY_INTERNAL_METHODS.__call__ } @@ -760,6 +768,10 @@ impl JsObject { /// [spec]: https://tc39.es/ecma262/#sec-isconstructor #[inline] #[must_use] + #[expect( + unpredictable_function_pointer_comparisons, + reason = "can only use `ptr::fn_addr_eq` on rustc 1.85" + )] pub fn is_constructor(&self) -> bool { self.inner.vtable.__construct__ != ORDINARY_INTERNAL_METHODS.__construct__ } diff --git a/core/engine/src/vm/opcode/concat/mod.rs b/core/engine/src/vm/opcode/concat/mod.rs index 09b39862817..349bec1752a 100644 --- a/core/engine/src/vm/opcode/concat/mod.rs +++ b/core/engine/src/vm/opcode/concat/mod.rs @@ -22,13 +22,7 @@ impl ConcatToString { let val = registers.get(*value); strings.push(val.to_string(context)?); } - let s = JsString::concat_array( - &strings - .iter() - .map(JsString::as_str) - .map(Into::into) - .collect::>(), - ); + let s = JsString::concat_array(&strings.iter().map(JsString::as_str).collect::>()); registers.set(string, s.into()); Ok(CompletionType::Normal) } diff --git a/core/parser/src/parser/expression/primary/object_initializer/mod.rs b/core/parser/src/parser/expression/primary/object_initializer/mod.rs index 7215767bd29..4f0d5869e3c 100644 --- a/core/parser/src/parser/expression/primary/object_initializer/mod.rs +++ b/core/parser/src/parser/expression/primary/object_initializer/mod.rs @@ -125,9 +125,9 @@ where if let Some(position) = duplicate_proto_position { if !cursor.json_parse() - && cursor.peek(0, interner)?.map_or(true, |token| { - token.kind() != &TokenKind::Punctuator(Punctuator::Assign) - }) + && cursor + .peek(0, interner)? + .is_none_or(|token| token.kind() != &TokenKind::Punctuator(Punctuator::Assign)) { return Err(Error::general( "Duplicate __proto__ fields are not allowed in object literals.", diff --git a/core/parser/src/parser/function/mod.rs b/core/parser/src/parser/function/mod.rs index acb78225430..44abc08a128 100644 --- a/core/parser/src/parser/function/mod.rs +++ b/core/parser/src/parser/function/mod.rs @@ -104,9 +104,10 @@ where params.push(next_param); - if cursor.peek(0, interner)?.map_or(true, |tok| { - tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen) - }) { + if cursor + .peek(0, interner)? + .is_none_or(|tok| tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen)) + { break; } @@ -120,9 +121,10 @@ where } cursor.expect(Punctuator::Comma, "parameter list", interner)?; - if cursor.peek(0, interner)?.map_or(true, |tok| { - tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen) - }) { + if cursor + .peek(0, interner)? + .is_none_or(|tok| tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen)) + { break; } } diff --git a/core/parser/src/parser/statement/mod.rs b/core/parser/src/parser/statement/mod.rs index a04b97e866a..0a8abcff697 100644 --- a/core/parser/src/parser/statement/mod.rs +++ b/core/parser/src/parser/statement/mod.rs @@ -151,7 +151,6 @@ where TokenKind::Keyword((Keyword::For, _)) => { ForStatement::new(self.allow_yield, self.allow_await, self.allow_return) .parse(cursor, interner) - .map(ast::Statement::from) } TokenKind::Keyword((Keyword::Return, _)) => { if self.allow_return.0 { diff --git a/core/parser/src/source/utf16.rs b/core/parser/src/source/utf16.rs index 16434ce1d24..7daf1bbe48c 100644 --- a/core/parser/src/source/utf16.rs +++ b/core/parser/src/source/utf16.rs @@ -61,5 +61,5 @@ fn is_low_surrogate(b: u16) -> bool { } fn code_point_from_surrogates(high: u16, low: u16) -> u32 { - ((u32::from(high & 0x3ff)) << 10 | u32::from(low & 0x3ff)) + 0x1_0000 + (((u32::from(high & 0x3ff)) << 10) | u32::from(low & 0x3ff)) + 0x1_0000 } diff --git a/core/parser/src/source/utf8.rs b/core/parser/src/source/utf8.rs index 41c8404b1c5..8a595ff7e9c 100644 --- a/core/parser/src/source/utf8.rs +++ b/core/parser/src/source/utf8.rs @@ -43,12 +43,12 @@ impl ReadChar for UTF8Input { // 5th bit in 0xE0 .. 0xEF is always clear, so `init` is still valid let z = self.next_byte()?.unwrap_or(0); let y_z = utf8_acc_cont_byte(u32::from(y & CONT_MASK), z); - ch = init << 12 | y_z; + ch = (init << 12) | y_z; if x >= 0xF0 { // [x y z w] case // use only the lower 3 bits of `init` let w = self.next_byte()?.unwrap_or(0); - ch = (init & 7) << 18 | utf8_acc_cont_byte(y_z, w); + ch = ((init & 7) << 18) | utf8_acc_cont_byte(y_z, w); } }; diff --git a/core/string/src/lib.rs b/core/string/src/lib.rs index b436b2e56c1..88af1352e03 100644 --- a/core/string/src/lib.rs +++ b/core/string/src/lib.rs @@ -970,13 +970,7 @@ impl From> for JsString { impl From<&[JsString]> for JsString { #[inline] fn from(value: &[JsString]) -> Self { - Self::concat_array( - &value - .iter() - .map(Self::as_str) - .map(Into::into) - .collect::>()[..], - ) + Self::concat_array(&value.iter().map(Self::as_str).collect::>()[..]) } }