diff --git a/boa_ast/src/expression/literal/array.rs b/boa_ast/src/expression/literal/array.rs index 9825223a0b1..ee0291f1386 100644 --- a/boa_ast/src/expression/literal/array.rs +++ b/boa_ast/src/expression/literal/array.rs @@ -60,9 +60,7 @@ impl ArrayLiteral { let mut bindings = Vec::new(); for (i, expr) in self.arr.iter().enumerate() { - let expr = if let Some(expr) = expr { - expr - } else { + let Some(expr) = expr else { bindings.push(ArrayPatternElement::Elision); continue; }; diff --git a/boa_ast/src/lib.rs b/boa_ast/src/lib.rs index 49ad17f7016..18dfb293ef8 100644 --- a/boa_ast/src/lib.rs +++ b/boa_ast/src/lib.rs @@ -91,8 +91,7 @@ #![allow( clippy::module_name_repetitions, clippy::too_many_lines, - clippy::option_if_let_else, - clippy::use_self + clippy::option_if_let_else )] mod position; diff --git a/boa_engine/src/builtins/date/mod.rs b/boa_engine/src/builtins/date/mod.rs index 2890737c3a9..132d61b951e 100644 --- a/boa_engine/src/builtins/date/mod.rs +++ b/boa_engine/src/builtins/date/mod.rs @@ -207,7 +207,7 @@ impl Date { // 3. If numberOfArgs = 0, then [] => { // a. Let dv be the time value (UTC) identifying the current time. - Date::default() + Self::default() } // 4. Else if numberOfArgs = 1, then // a. Let value be values[0]. @@ -229,7 +229,7 @@ impl Date { // 1. Assert: The next step never returns an abrupt completion because v is a String. // 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the // parse method (21.4.3.2). - Date( + Self( str.to_std_string() .ok() .and_then(|s| { @@ -242,7 +242,7 @@ impl Date { v => { // Directly convert to integer // 1. Let tv be ? ToNumber(v). - Date( + Self( v.to_integer_or_nan(context)? .as_integer() // d. Let dv be TimeClip(tv). @@ -256,7 +256,7 @@ impl Date { // 5. Else, _ => { // Separating this into its own function to simplify the logic. - Date( + Self( Self::construct_date(args, context)? .and_then(|dt| Local.from_local_datetime(&dt).earliest()) .map(|dt| dt.naive_utc()), @@ -717,7 +717,7 @@ impl Date { ); // 7. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 8. Return u. Ok(t.as_value()) @@ -748,7 +748,7 @@ impl Date { .earliest() .as_ref() .map(DateTime::naive_utc) else { - *t = Date(None); + *t = Self(None); return Ok(t.as_value()) }; datetime @@ -785,7 +785,7 @@ impl Date { ); // 8. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 9. Return u. Ok(t.as_value()) @@ -851,7 +851,7 @@ impl Date { ); // 13. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 14. Return u. Ok(t.as_value()) @@ -892,7 +892,7 @@ impl Date { ); // 7. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 8. Return u. Ok(t.as_value()) @@ -948,7 +948,7 @@ impl Date { ); // 11. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 12. Return u. Ok(t.as_value()) @@ -997,7 +997,7 @@ impl Date { ); // 9. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 10. Return u. Ok(t.as_value()) @@ -1045,7 +1045,7 @@ impl Date { ); // 9. Set the [[DateValue]] internal slot of this Date object to u. - *t = Date(datetime); + *t = Self(datetime); // 10. Return u. Ok(t.as_value()) @@ -1085,14 +1085,14 @@ impl Date { .as_ref() .map(DateTime::naive_utc) }) else { - *t = Date(None); + *t = Self(None); return Ok(t.as_value()); }; // 4. If y is NaN, then let Some(mut year) = year.as_integer() else { // a. Set the [[DateValue]] internal slot of this Date object to NaN. - *t = Date(None); + *t = Self(None); // b. Return NaN. return Ok(t.as_value()); @@ -1116,7 +1116,7 @@ impl Date { ); // 10. Set the [[DateValue]] internal slot of this Date object to TimeClip(date). - *t = Date(datetime); + *t = Self(datetime); // 11. Return the value of the [[DateValue]] internal slot of this Date object. Ok(t.as_value()) @@ -1150,7 +1150,7 @@ impl Date { .and_then(NaiveDateTime::from_timestamp_millis); // 4. Set the [[DateValue]] internal slot of this Date object to v. - *t = Date(timestamp); + *t = Self(timestamp); // 5. Return v. Ok(t.as_value()) @@ -1410,7 +1410,7 @@ impl Date { _context: &mut Context<'_>, ) -> JsResult { // 1. Return ? thisTimeValue(this value). - Ok(Date(this_time_value(this)?).as_value()) + Ok(Self(this_time_value(this)?).as_value()) } /// [`Date.prototype [ @@toPrimitive ] ( hint )`][spec]. diff --git a/boa_engine/src/builtins/function/mod.rs b/boa_engine/src/builtins/function/mod.rs index abebc772b38..9964005603c 100644 --- a/boa_engine/src/builtins/function/mod.rs +++ b/boa_engine/src/builtins/function/mod.rs @@ -781,7 +781,9 @@ impl BuiltInFunctionObject { let target_name = target.get("name", context)?; // 9. If Type(targetName) is not String, set targetName to the empty String. - let target_name = target_name.as_string().map_or(js_string!(), Clone::clone); + let target_name = target_name + .as_string() + .map_or_else(JsString::default, Clone::clone); // 10. Perform SetFunctionName(F, targetName, "bound"). set_function_name(&f, &target_name.into(), Some(js_string!("bound")), context); diff --git a/boa_engine/src/builtins/intl/collator/mod.rs b/boa_engine/src/builtins/intl/collator/mod.rs index 8fcca3d15e7..13a726f32a7 100644 --- a/boa_engine/src/builtins/intl/collator/mod.rs +++ b/boa_engine/src/builtins/intl/collator/mod.rs @@ -343,7 +343,7 @@ impl Collator { get_prototype_from_constructor(new_target, StandardConstructors::collator, context)?; let collator = JsObject::from_proto_and_data( prototype, - ObjectData::collator(Collator { + ObjectData::collator(Self { locale, collation, numeric, diff --git a/boa_engine/src/builtins/intl/collator/options.rs b/boa_engine/src/builtins/intl/collator/options.rs index 928c038b0ac..a2c9e5a540d 100644 --- a/boa_engine/src/builtins/intl/collator/options.rs +++ b/boa_engine/src/builtins/intl/collator/options.rs @@ -16,10 +16,10 @@ impl Sensitivity { /// Converts the sensitivity option to the equivalent ICU4X collator options. pub(crate) const fn to_collator_options(self) -> (Strength, CaseLevel) { match self { - Sensitivity::Base => (Strength::Primary, CaseLevel::Off), - Sensitivity::Accent => (Strength::Secondary, CaseLevel::Off), - Sensitivity::Case => (Strength::Primary, CaseLevel::On), - Sensitivity::Variant => (Strength::Tertiary, CaseLevel::On), + Self::Base => (Strength::Primary, CaseLevel::Off), + Self::Accent => (Strength::Secondary, CaseLevel::Off), + Self::Case => (Strength::Primary, CaseLevel::On), + Self::Variant => (Strength::Tertiary, CaseLevel::On), } } } diff --git a/boa_engine/src/builtins/intl/date_time_format.rs b/boa_engine/src/builtins/intl/date_time_format.rs index a4c90acc03e..33fe7938cdf 100644 --- a/boa_engine/src/builtins/intl/date_time_format.rs +++ b/boa_engine/src/builtins/intl/date_time_format.rs @@ -27,10 +27,10 @@ use super::options::OptionType; impl OptionType for HourCycle { fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult { match value.to_string(context)?.to_std_string_escaped().as_str() { - "h11" => Ok(HourCycle::H11), - "h12" => Ok(HourCycle::H12), - "h23" => Ok(HourCycle::H23), - "h24" => Ok(HourCycle::H24), + "h11" => Ok(Self::H11), + "h12" => Ok(Self::H12), + "h23" => Ok(Self::H23), + "h24" => Ok(Self::H24), _ => Err(JsNativeError::range() .with_message("provided string was not `h11`, `h12`, `h23` or `h24`") .into()), diff --git a/boa_engine/src/builtins/intl/list_format/mod.rs b/boa_engine/src/builtins/intl/list_format/mod.rs index 42c5f20c4fc..af6a6c922fa 100644 --- a/boa_engine/src/builtins/intl/list_format/mod.rs +++ b/boa_engine/src/builtins/intl/list_format/mod.rs @@ -148,7 +148,7 @@ impl ListFormat { get_prototype_from_constructor(new_target, StandardConstructors::list_format, context)?; let list_format = JsObject::from_proto_and_data( prototype, - ObjectData::list_format(ListFormat { + ObjectData::list_format(Self { formatter: context .icu() .provider() @@ -249,15 +249,15 @@ impl ListFormat { impl Part { const fn typ(&self) -> &'static str { match self { - Part::Literal(_) => "literal", - Part::Element(_) => "element", + Self::Literal(_) => "literal", + Self::Element(_) => "element", } } #[allow(clippy::missing_const_for_fn)] fn value(self) -> String { match self { - Part::Literal(s) | Part::Element(s) => s, + Self::Literal(s) | Self::Element(s) => s, } } } @@ -276,7 +276,7 @@ impl ListFormat { } impl PartsWrite for WriteString { - type SubPartsWrite = WriteString; + type SubPartsWrite = Self; fn with_part( &mut self, diff --git a/boa_engine/src/builtins/intl/locale/options.rs b/boa_engine/src/builtins/intl/locale/options.rs index 94c899a60f9..17660aad5b2 100644 --- a/boa_engine/src/builtins/intl/locale/options.rs +++ b/boa_engine/src/builtins/intl/locale/options.rs @@ -7,7 +7,7 @@ impl OptionType for Value { let val = value .to_string(context)? .to_std_string_escaped() - .parse::() + .parse::() .map_err(|e| JsNativeError::range().with_message(e.to_string()))?; if val.as_tinystr_slice().is_empty() { diff --git a/boa_engine/src/builtins/intl/options.rs b/boa_engine/src/builtins/intl/options.rs index 0d963e39328..c444fc87b2e 100644 --- a/boa_engine/src/builtins/intl/options.rs +++ b/boa_engine/src/builtins/intl/options.rs @@ -94,9 +94,9 @@ impl OptionTypeParsable for LocaleMatcher {} impl OptionType for CaseFirst { fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult { match value.to_string(context)?.to_std_string_escaped().as_str() { - "upper" => Ok(CaseFirst::UpperFirst), - "lower" => Ok(CaseFirst::LowerFirst), - "false" => Ok(CaseFirst::Off), + "upper" => Ok(Self::UpperFirst), + "lower" => Ok(Self::LowerFirst), + "false" => Ok(Self::Off), _ => Err(JsNativeError::range() .with_message("provided string was not `upper`, `lower` or `false`") .into()), diff --git a/boa_engine/src/builtins/math/tests.rs b/boa_engine/src/builtins/math/tests.rs index c86219ed6f2..582a6610639 100644 --- a/boa_engine/src/builtins/math/tests.rs +++ b/boa_engine/src/builtins/math/tests.rs @@ -93,7 +93,7 @@ fn asinh() { let a = forward_val(&mut context, "a").unwrap(); let b = forward_val(&mut context, "b").unwrap(); - assert_eq!(a.to_number(&mut context).unwrap(), 0.881_373_587_019_542_9); + assert_eq!(a.to_number(&mut context).unwrap(), 0.881_373_587_019_543); assert_eq!(b.to_number(&mut context).unwrap(), 0_f64); } diff --git a/boa_engine/src/builtins/object/mod.rs b/boa_engine/src/builtins/object/mod.rs index 67fe1fccb21..7f5bccb92f3 100644 --- a/boa_engine/src/builtins/object/mod.rs +++ b/boa_engine/src/builtins/object/mod.rs @@ -203,9 +203,8 @@ impl Object { }; // 3. If Type(O) is not Object, return undefined. - let object = match this { - JsValue::Object(object) => object, - _ => return Ok(JsValue::undefined()), + let JsValue::Object(object) = this else { + return Ok(JsValue::undefined()); }; // 4. Let status be ? O.[[SetPrototypeOf]](proto). @@ -517,9 +516,7 @@ impl Object { context: &mut Context<'_>, ) -> JsValue { // 1. If Desc is undefined, return undefined. - let desc = if let Some(desc) = desc { - desc - } else { + let Some(desc)= desc else { return JsValue::undefined(); }; @@ -892,9 +889,8 @@ impl Object { args: &[JsValue], context: &mut Context<'_>, ) -> JsResult { - let key = match args.get(0) { - None => return Ok(JsValue::new(false)), - Some(key) => key, + let Some(key) = args.get(0) else { + return Ok(JsValue::new(false)); }; let key = key.to_property_key(context)?; diff --git a/boa_engine/src/builtins/promise/mod.rs b/boa_engine/src/builtins/promise/mod.rs index 87aab138543..1cdb0afbc70 100644 --- a/boa_engine/src/builtins/promise/mod.rs +++ b/boa_engine/src/builtins/promise/mod.rs @@ -235,7 +235,7 @@ impl PromiseCapability { // 9. Set promiseCapability.[[Promise]] to promise. // 10. Return promiseCapability. - Ok(PromiseCapability { + Ok(Self { promise, resolve, reject, diff --git a/boa_engine/src/builtins/regexp/mod.rs b/boa_engine/src/builtins/regexp/mod.rs index 169b5f81ae2..d46ff18fd98 100644 --- a/boa_engine/src/builtins/regexp/mod.rs +++ b/boa_engine/src/builtins/regexp/mod.rs @@ -609,9 +609,7 @@ impl RegExp { ) -> JsResult { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. - let object = if let Some(object) = this.as_object() { - object - } else { + let Some(object) = this.as_object() else { return Err(JsNativeError::typ() .with_message("RegExp.prototype.source method called on incompatible value") .into()); diff --git a/boa_engine/src/builtins/string/mod.rs b/boa_engine/src/builtins/string/mod.rs index 055957f4c54..ecb8464d172 100644 --- a/boa_engine/src/builtins/string/mod.rs +++ b/boa_engine/src/builtins/string/mod.rs @@ -2355,9 +2355,8 @@ pub(crate) fn get_substitution( /// [spec]: https://tc39.es/ecma262/#sec-isregexp fn is_reg_exp(argument: &JsValue, context: &mut Context<'_>) -> JsResult { // 1. If Type(argument) is not Object, return false. - let argument = match argument { - JsValue::Object(o) => o, - _ => return Ok(false), + let JsValue::Object(argument) = argument else { + return Ok(false); }; is_reg_exp_object(argument, context) diff --git a/boa_engine/src/builtins/weak/weak_ref.rs b/boa_engine/src/builtins/weak/weak_ref.rs index f6fcfcc03da..32cf0a52f45 100644 --- a/boa_engine/src/builtins/weak/weak_ref.rs +++ b/boa_engine/src/builtins/weak/weak_ref.rs @@ -35,7 +35,7 @@ impl BuiltIn for WeakRef { let _timer = Profiler::global().start_event(Self::NAME, "init"); ConstructorBuilder::with_standard_constructor( context, - WeakRef::constructor, + Self::constructor, context.intrinsics().constructors().weak_ref().clone(), ) .name(Self::NAME) @@ -45,7 +45,7 @@ impl BuiltIn for WeakRef { "WeakRef", Attribute::CONFIGURABLE, ) - .method(WeakRef::deref, "deref", 0) + .method(Self::deref, "deref", 0) .build() .conv::() .pipe(Some) diff --git a/boa_engine/src/bytecompiler/jump_control.rs b/boa_engine/src/bytecompiler/jump_control.rs index f8c52fa20d5..eddf4d8b3c0 100644 --- a/boa_engine/src/bytecompiler/jump_control.rs +++ b/boa_engine/src/bytecompiler/jump_control.rs @@ -44,7 +44,7 @@ bitflags! { impl Default for JumpControlInfoFlags { fn default() -> Self { - JumpControlInfoFlags::empty() + Self::empty() } } diff --git a/boa_engine/src/job.rs b/boa_engine/src/job.rs index a4a1cf735df..ed1df64b5ae 100644 --- a/boa_engine/src/job.rs +++ b/boa_engine/src/job.rs @@ -107,7 +107,7 @@ impl Debug for JobCallback { impl JobCallback { /// Creates a new `JobCallback`. pub fn new(callback: JsFunction, host_defined: T) -> Self { - JobCallback { + Self { callback, host_defined: Box::new(host_defined), } diff --git a/boa_engine/src/lib.rs b/boa_engine/src/lib.rs index c8303cbae6e..11ebecbb2c9 100644 --- a/boa_engine/src/lib.rs +++ b/boa_engine/src/lib.rs @@ -95,7 +95,7 @@ clippy::missing_errors_doc, clippy::let_unit_value, clippy::option_if_let_else, - // Currently derive macros are linted. Should be fixed in 1.66. See https://github.com/rust-lang/rust-clippy/pull/9454 + // Currently lints in places where `Self` would have a type parameter. clippy::use_self, // It may be worth to look if we can fix the issues highlighted by these lints. @@ -223,18 +223,14 @@ pub(crate) fn check_output(actions: &[TestAction]) { assert_eq!( &forward(&mut context, case), expected, - "Test case {} ('{}')", - i, - case + "Test case {i} ('{case}')" ); i += 1; } TestAction::TestStartsWith(case, expected) => { assert!( &forward(&mut context, case).starts_with(expected), - "Test case {} ('{}')", - i, - case + "Test case {i} ('{case}')", ); i += 1; } diff --git a/boa_engine/src/object/internal_methods/array.rs b/boa_engine/src/object/internal_methods/array.rs index 247a722947a..bbd86b1244d 100644 --- a/boa_engine/src/object/internal_methods/array.rs +++ b/boa_engine/src/object/internal_methods/array.rs @@ -111,12 +111,9 @@ fn array_set_length( context: &mut Context<'_>, ) -> JsResult { // 1. If Desc.[[Value]] is absent, then - let new_len_val = match desc.value() { - Some(value) => value, - _ => { - // a. Return OrdinaryDefineOwnProperty(A, "length", Desc). - return super::ordinary_define_own_property(obj, "length".into(), desc, context); - } + let Some(new_len_val) = desc.value() else { + // a. Return OrdinaryDefineOwnProperty(A, "length", Desc). + return super::ordinary_define_own_property(obj, "length".into(), desc, context); }; // 3. Let newLen be ? ToUint32(Desc.[[Value]]). diff --git a/boa_engine/src/object/internal_methods/mod.rs b/boa_engine/src/object/internal_methods/mod.rs index e9755e2f3e2..5d974367797 100644 --- a/boa_engine/src/object/internal_methods/mod.rs +++ b/boa_engine/src/object/internal_methods/mod.rs @@ -608,10 +608,9 @@ pub(crate) fn ordinary_set( return Ok(false); } - let receiver = match receiver.as_object() { - Some(obj) => obj, - // b. If Type(Receiver) is not Object, return false. - _ => return Ok(false), + // b. If Type(Receiver) is not Object, return false. + let Some(receiver) = receiver.as_object() else { + return Ok(false); }; // c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). diff --git a/boa_engine/src/object/operations.rs b/boa_engine/src/object/operations.rs index 68797c8f6e2..c6cac15444d 100644 --- a/boa_engine/src/object/operations.rs +++ b/boa_engine/src/object/operations.rs @@ -938,7 +938,7 @@ impl JsObject { /// [spec]: https://tc39.es/ecma262/#sec-initializeinstanceelements pub(crate) fn initialize_instance_elements( &self, - constructor: &JsObject, + constructor: &Self, context: &mut Context<'_>, ) -> JsResult<()> { let constructor_borrow = constructor.borrow(); @@ -1110,10 +1110,10 @@ impl JsValue { #[inline] pub(crate) fn call( &self, - this: &JsValue, - args: &[JsValue], + this: &Self, + args: &[Self], context: &mut Context<'_>, - ) -> JsResult { + ) -> JsResult { self.as_callable() .ok_or_else(|| { JsNativeError::typ().with_message(format!( diff --git a/boa_engine/src/string/mod.rs b/boa_engine/src/string/mod.rs index 1783bcfa9d1..e517d0fdd9b 100644 --- a/boa_engine/src/string/mod.rs +++ b/boa_engine/src/string/mod.rs @@ -781,7 +781,7 @@ impl FromStr for JsString { type Err = Infallible; fn from_str(s: &str) -> Result { - Ok(JsString::from(s)) + Ok(Self::from(s)) } } diff --git a/boa_engine/src/symbol.rs b/boa_engine/src/symbol.rs index dcbc9740006..925dd6f9e03 100644 --- a/boa_engine/src/symbol.rs +++ b/boa_engine/src/symbol.rs @@ -80,19 +80,19 @@ enum WellKnown { impl WellKnown { const fn description(self) -> JsString { match self { - WellKnown::AsyncIterator => StaticJsStrings::symbol_async_iterator(), - WellKnown::HasInstance => StaticJsStrings::symbol_has_instance(), - WellKnown::IsConcatSpreadable => StaticJsStrings::symbol_is_concat_spreadable(), - WellKnown::Iterator => StaticJsStrings::symbol_iterator(), - WellKnown::Match => StaticJsStrings::symbol_match(), - WellKnown::MatchAll => StaticJsStrings::symbol_match_all(), - WellKnown::Replace => StaticJsStrings::symbol_replace(), - WellKnown::Search => StaticJsStrings::symbol_search(), - WellKnown::Species => StaticJsStrings::symbol_species(), - WellKnown::Split => StaticJsStrings::symbol_split(), - WellKnown::ToPrimitive => StaticJsStrings::symbol_to_primitive(), - WellKnown::ToStringTag => StaticJsStrings::symbol_to_string_tag(), - WellKnown::Unscopables => StaticJsStrings::symbol_unscopables(), + Self::AsyncIterator => StaticJsStrings::symbol_async_iterator(), + Self::HasInstance => StaticJsStrings::symbol_has_instance(), + Self::IsConcatSpreadable => StaticJsStrings::symbol_is_concat_spreadable(), + Self::Iterator => StaticJsStrings::symbol_iterator(), + Self::Match => StaticJsStrings::symbol_match(), + Self::MatchAll => StaticJsStrings::symbol_match_all(), + Self::Replace => StaticJsStrings::symbol_replace(), + Self::Search => StaticJsStrings::symbol_search(), + Self::Species => StaticJsStrings::symbol_species(), + Self::Split => StaticJsStrings::symbol_split(), + Self::ToPrimitive => StaticJsStrings::symbol_to_primitive(), + Self::ToStringTag => StaticJsStrings::symbol_to_string_tag(), + Self::Unscopables => StaticJsStrings::symbol_unscopables(), } } diff --git a/boa_engine/src/tagged.rs b/boa_engine/src/tagged.rs index 28b8af40054..d598dfdf737 100644 --- a/boa_engine/src/tagged.rs +++ b/boa_engine/src/tagged.rs @@ -50,7 +50,7 @@ impl Tagged { debug_assert!(std::mem::align_of::() >= 2); let addr = (tag << 1) | 1; // SAFETY: `addr` is never zero, since we always set its LSB to 1 - unsafe { Tagged(NonNull::new_unchecked(sptr::invalid_mut(addr))) } + unsafe { Self(NonNull::new_unchecked(sptr::invalid_mut(addr))) } } /// Creates a new `Tagged` pointer from a raw pointer. @@ -65,7 +65,7 @@ impl Tagged { pub(crate) const unsafe fn from_ptr(ptr: *mut T) -> Tagged { debug_assert!(std::mem::align_of::() >= 2); // SAFETY: the caller must ensure the invariants hold. - unsafe { Tagged(NonNull::new_unchecked(ptr)) } + unsafe { Self(NonNull::new_unchecked(ptr)) } } /// Creates a new `Tagged` pointer from a `NonNull` pointer. @@ -75,7 +75,7 @@ impl Tagged { /// - `T` must have an alignment of at least 2. pub(crate) const fn from_non_null(ptr: NonNull) -> Tagged { debug_assert!(std::mem::align_of::() >= 2); - Tagged(ptr) + Self(ptr) } /// Unwraps the `Tagged` pointer. diff --git a/boa_engine/src/value/integer.rs b/boa_engine/src/value/integer.rs index 5b9e078c85b..2ebc0dad1af 100644 --- a/boa_engine/src/value/integer.rs +++ b/boa_engine/src/value/integer.rs @@ -121,7 +121,6 @@ impl IntegerOrNan { impl From for IntegerOrNan { fn from(ior: IntegerOrInfinity) -> Self { - ior.as_integer() - .map_or(IntegerOrNan::Nan, IntegerOrNan::Integer) + ior.as_integer().map_or(Self::Nan, IntegerOrNan::Integer) } } diff --git a/boa_engine/src/vm/flowgraph/color.rs b/boa_engine/src/vm/flowgraph/color.rs index cf86ee31102..bf5587c7866 100644 --- a/boa_engine/src/vm/flowgraph/color.rs +++ b/boa_engine/src/vm/flowgraph/color.rs @@ -77,13 +77,13 @@ impl Color { impl Display for Color { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Color::None => f.write_str(""), - Color::Red => f.write_str("red"), - Color::Green => f.write_str("green"), - Color::Blue => f.write_str("blue"), - Color::Yellow => f.write_str("yellow"), - Color::Purple => f.write_str("purple"), - Color::Rgb { r, g, b } => write!(f, "#{r:02X}{b:02X}{g:02X}"), + Self::None => f.write_str(""), + Self::Red => f.write_str("red"), + Self::Green => f.write_str("green"), + Self::Blue => f.write_str("blue"), + Self::Yellow => f.write_str("yellow"), + Self::Purple => f.write_str("purple"), + Self::Rgb { r, g, b } => write!(f, "#{r:02X}{b:02X}{g:02X}"), } } } diff --git a/boa_engine/src/vm/flowgraph/graph.rs b/boa_engine/src/vm/flowgraph/graph.rs index 137114fc589..13d0ca646cd 100644 --- a/boa_engine/src/vm/flowgraph/graph.rs +++ b/boa_engine/src/vm/flowgraph/graph.rs @@ -83,8 +83,8 @@ impl SubGraph { /// Create a subgraph in this subgraph. #[inline] - pub fn subgraph(&mut self, label: String) -> &mut SubGraph { - self.subgraphs.push(SubGraph::new(label)); + pub fn subgraph(&mut self, label: String) -> &mut Self { + self.subgraphs.push(Self::new(label)); let result = self .subgraphs .last_mut() @@ -248,7 +248,7 @@ impl Graph { #[inline] #[must_use] pub fn new(direction: Direction) -> Self { - Graph { + Self { subgraphs: Vec::default(), direction, } diff --git a/boa_examples/src/bin/loadfile.rs b/boa_examples/src/bin/loadfile.rs index b88fe490fc9..56ef6d50049 100644 --- a/boa_examples/src/bin/loadfile.rs +++ b/boa_examples/src/bin/loadfile.rs @@ -26,6 +26,6 @@ fn main() { } }; } - Err(msg) => eprintln!("Error: {}", msg), + Err(msg) => eprintln!("Error: {msg}"), } } diff --git a/boa_examples/src/bin/modulehandler.rs b/boa_examples/src/bin/modulehandler.rs index ae400fbb4df..ff0cc63d8aa 100644 --- a/boa_examples/src/bin/modulehandler.rs +++ b/boa_examples/src/bin/modulehandler.rs @@ -45,7 +45,7 @@ fn require(_: &JsValue, args: &[JsValue], ctx: &mut Context<'_>) -> JsResult BorrowState { + const fn borrowed(self) -> BorrowState { match self.0 & !ROOT { UNUSED => BorrowState::Unused, WRITING => BorrowState::Writing, @@ -44,18 +44,18 @@ impl BorrowFlag { } /// Check whether the borrow bit is flagged. - pub(crate) const fn rooted(self) -> bool { + const fn rooted(self) -> bool { self.0 & ROOT > 0 } /// Set the `BorrowFlag`'s state to writing. - pub(crate) const fn set_writing(self) -> Self { + const fn set_writing(self) -> Self { // Set every bit other than the root bit, which is preserved Self(self.0 | WRITING) } /// Remove the root flag on `BorrowFlag` - pub(crate) const fn set_unused(self) -> Self { + const fn set_unused(self) -> Self { // Clear every bit other than the root bit, which is preserved Self(self.0 & ROOT) } @@ -65,7 +65,7 @@ impl BorrowFlag { /// # Panic /// - This method will panic if the current `BorrowState` is writing. /// - This method will panic after incrementing if the borrow count overflows. - pub(crate) fn add_reading(self) -> Self { + fn add_reading(self) -> Self { assert!(self.borrowed() != BorrowState::Writing); // Add 1 to the integer starting at the second binary digit. As our // borrowstate is not writing, we know that overflow cannot happen, so @@ -86,7 +86,7 @@ impl BorrowFlag { /// /// # Panic /// - This method will panic if the current `BorrowState` is not reading. - pub(crate) fn sub_reading(self) -> Self { + fn sub_reading(self) -> Self { assert!(self.borrowed() == BorrowState::Reading); // Subtract 1 from the integer starting at the second binary digit. As // our borrowstate is not writing or unused, we know that overflow or @@ -98,7 +98,7 @@ impl BorrowFlag { } /// Set the root flag on the `BorrowFlag`. - pub(crate) fn set_rooted(self, rooted: bool) -> Self { + fn set_rooted(self, rooted: bool) -> Self { // Preserve the non-root bits Self((self.0 & !ROOT) | (usize::from(rooted))) } @@ -118,8 +118,8 @@ impl Debug for BorrowFlag { /// /// This object is a `RefCell` that can be used inside of a `Gc`. pub struct GcRefCell { - pub(crate) flags: Cell, - pub(crate) cell: UnsafeCell, + flags: Cell, + cell: UnsafeCell, } impl GcRefCell { @@ -296,8 +296,8 @@ unsafe impl Trace for GcRefCell { /// A wrapper type for an immutably borrowed value from a `GcCell`. pub struct GcRef<'a, T: ?Sized + 'static> { - pub(crate) flags: &'a Cell, - pub(crate) value: &'a T, + flags: &'a Cell, + value: &'a T, } impl<'a, T: ?Sized> GcRef<'a, T> { diff --git a/boa_parser/src/parser/cursor/buffered_lexer/mod.rs b/boa_parser/src/parser/cursor/buffered_lexer/mod.rs index 2256bd1cd81..810c7672e27 100644 --- a/boa_parser/src/parser/cursor/buffered_lexer/mod.rs +++ b/boa_parser/src/parser/cursor/buffered_lexer/mod.rs @@ -215,8 +215,7 @@ where ) -> ParseResult> { assert!( skip_n <= MAX_PEEK_SKIP, - "you cannot skip more than {} elements", - MAX_PEEK_SKIP + "you cannot skip more than {MAX_PEEK_SKIP} elements", ); let mut read_index = self.read_index; diff --git a/boa_parser/src/parser/expression/assignment/arrow_function.rs b/boa_parser/src/parser/expression/assignment/arrow_function.rs index 527c0704cc4..dc4f42a9416 100644 --- a/boa_parser/src/parser/expression/assignment/arrow_function.rs +++ b/boa_parser/src/parser/expression/assignment/arrow_function.rs @@ -81,8 +81,8 @@ where let _timer = Profiler::global().start_event("ArrowFunction", "Parsing"); let next_token = cursor.peek(0, interner).or_abrupt()?; - let (params, params_start_position) = if let TokenKind::Punctuator(Punctuator::OpenParen) = - &next_token.kind() + let (params, params_start_position) = if next_token.kind() + == &TokenKind::Punctuator(Punctuator::OpenParen) { // CoverParenthesizedExpressionAndArrowParameterList let params_start_position = cursor diff --git a/boa_parser/src/parser/expression/assignment/async_arrow_function.rs b/boa_parser/src/parser/expression/assignment/async_arrow_function.rs index ff5a858d474..c1cc307b53d 100644 --- a/boa_parser/src/parser/expression/assignment/async_arrow_function.rs +++ b/boa_parser/src/parser/expression/assignment/async_arrow_function.rs @@ -77,8 +77,8 @@ 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 let TokenKind::Punctuator(Punctuator::OpenParen) = - &next_token.kind() + 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)? diff --git a/boa_parser/src/parser/expression/assignment/exponentiation.rs b/boa_parser/src/parser/expression/assignment/exponentiation.rs index b0b85459dde..4c7da772577 100644 --- a/boa_parser/src/parser/expression/assignment/exponentiation.rs +++ b/boa_parser/src/parser/expression/assignment/exponentiation.rs @@ -88,7 +88,7 @@ where let lhs = UpdateExpression::new(self.name, self.allow_yield, self.allow_await) .parse(cursor, interner)?; if let Some(tok) = cursor.peek(0, interner)? { - if let TokenKind::Punctuator(Punctuator::Exp) = tok.kind() { + if tok.kind() == &TokenKind::Punctuator(Punctuator::Exp) { cursor.advance(interner); return Ok(Binary::new( ArithmeticOp::Exp.into(), diff --git a/boa_parser/src/parser/expression/primary/object_initializer/mod.rs b/boa_parser/src/parser/expression/primary/object_initializer/mod.rs index bb7cff17efa..31b8219b156 100644 --- a/boa_parser/src/parser/expression/primary/object_initializer/mod.rs +++ b/boa_parser/src/parser/expression/primary/object_initializer/mod.rs @@ -213,7 +213,7 @@ where let token = cursor.peek(0, interner).or_abrupt()?; let position = token.span().start(); - if let TokenKind::Punctuator(Punctuator::Mul) = token.kind() { + if token.kind() == &TokenKind::Punctuator(Punctuator::Mul) { let (class_element_name, method) = AsyncGeneratorMethod::new(self.allow_yield, self.allow_await) .parse(cursor, interner)?; @@ -223,17 +223,12 @@ where return Err(Error::general("invalid super usage", position)); } - let property_name = - if let property::ClassElementName::PropertyName(property_name) = - class_element_name - { - property_name - } else { - return Err(Error::general( - "private identifiers not allowed in object literal", - position, - )); - }; + let property::ClassElementName::PropertyName(property_name) = class_element_name else { + return Err(Error::general( + "private identifiers not allowed in object literal", + position, + )); + }; return Ok(property::PropertyDefinition::MethodDefinition( property_name, diff --git a/boa_parser/src/parser/statement/declaration/hoistable/mod.rs b/boa_parser/src/parser/statement/declaration/hoistable/mod.rs index bd2bb4b4b94..44e15b4170a 100644 --- a/boa_parser/src/parser/statement/declaration/hoistable/mod.rs +++ b/boa_parser/src/parser/statement/declaration/hoistable/mod.rs @@ -90,7 +90,7 @@ where } TokenKind::Keyword((Keyword::Function, false)) => { let next_token = cursor.peek(1, interner).or_abrupt()?; - if let TokenKind::Punctuator(Punctuator::Mul) = next_token.kind() { + if next_token.kind() == &TokenKind::Punctuator(Punctuator::Mul) { GeneratorDeclaration::new(self.allow_yield, self.allow_await, self.is_default) .parse(cursor, interner) .map(Declaration::from) @@ -102,7 +102,7 @@ where } TokenKind::Keyword((Keyword::Async, false)) => { let next_token = cursor.peek(2, interner).or_abrupt()?; - if let TokenKind::Punctuator(Punctuator::Mul) = next_token.kind() { + if next_token.kind() == &TokenKind::Punctuator(Punctuator::Mul) { AsyncGeneratorDeclaration::new( self.allow_yield, self.allow_await, diff --git a/boa_parser/src/parser/statement/mod.rs b/boa_parser/src/parser/statement/mod.rs index c2452a55cb7..3d47d4cda22 100644 --- a/boa_parser/src/parser/statement/mod.rs +++ b/boa_parser/src/parser/statement/mod.rs @@ -632,7 +632,7 @@ where } if let Some(peek_token) = cursor.peek(0, interner)? { - if let TokenKind::Punctuator(Punctuator::Comma) = peek_token.kind() { + if peek_token.kind() == &TokenKind::Punctuator(Punctuator::Comma) { cursor.expect( TokenKind::Punctuator(Punctuator::Comma), "object binding pattern", @@ -830,7 +830,7 @@ where } if let Some(peek_token) = cursor.peek(0, interner)? { - if let TokenKind::Punctuator(Punctuator::Comma) = peek_token.kind() { + if peek_token.kind() == &TokenKind::Punctuator(Punctuator::Comma) { cursor.expect( TokenKind::Punctuator(Punctuator::Comma), "array binding pattern", diff --git a/boa_tester/src/main.rs b/boa_tester/src/main.rs index f62002f099b..c012b59cc8c 100644 --- a/boa_tester/src/main.rs +++ b/boa_tester/src/main.rs @@ -60,7 +60,6 @@ clippy::nursery, )] #![allow( - clippy::use_self, clippy::too_many_lines, clippy::redundant_pub_crate, clippy::cast_precision_loss,