Skip to content

Commit

Permalink
Fix rust 1.67 lints (#2567)
Browse files Browse the repository at this point in the history
This Pull Request changes the following:

- Fix rust 1.67 lints
  • Loading branch information
raskad committed Jan 27, 2023
1 parent 753cab6 commit e6a1c37
Show file tree
Hide file tree
Showing 39 changed files with 128 additions and 152 deletions.
4 changes: 1 addition & 3 deletions boa_ast/src/expression/literal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 1 addition & 2 deletions boa_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions boa_engine/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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| {
Expand All @@ -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).
Expand All @@ -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()),
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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());
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -1410,7 +1410,7 @@ impl Date {
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 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].
Expand Down
4 changes: 3 additions & 1 deletion boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/intl/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/builtins/intl/collator/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/builtins/intl/date_time_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use super::options::OptionType;
impl OptionType for HourCycle {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
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()),
Expand Down
10 changes: 5 additions & 5 deletions boa_engine/src/builtins/intl/list_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
}
}
}
Expand All @@ -276,7 +276,7 @@ impl ListFormat {
}

impl PartsWrite for WriteString {
type SubPartsWrite = WriteString;
type SubPartsWrite = Self;

fn with_part(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/intl/locale/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl OptionType for Value {
let val = value
.to_string(context)?
.to_std_string_escaped()
.parse::<Value>()
.parse::<Self>()
.map_err(|e| JsNativeError::range().with_message(e.to_string()))?;

if val.as_tinystr_slice().is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions boa_engine/src/builtins/intl/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl OptionTypeParsable for LocaleMatcher {}
impl OptionType for CaseFirst {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
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()),
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/math/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 5 additions & 9 deletions boa_engine/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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();
};

Expand Down Expand Up @@ -892,9 +889,8 @@ impl Object {
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
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)?;
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl PromiseCapability {

// 9. Set promiseCapability.[[Promise]] to promise.
// 10. Return promiseCapability.
Ok(PromiseCapability {
Ok(Self {
promise,
resolve,
reject,
Expand Down
4 changes: 1 addition & 3 deletions boa_engine/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,7 @@ impl RegExp {
) -> JsResult<JsValue> {
// 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());
Expand Down
5 changes: 2 additions & 3 deletions boa_engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
// 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)
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/weak/weak_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -45,7 +45,7 @@ impl BuiltIn for WeakRef {
"WeakRef",
Attribute::CONFIGURABLE,
)
.method(WeakRef::deref, "deref", 0)
.method(Self::deref, "deref", 0)
.build()
.conv::<JsValue>()
.pipe(Some)
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/bytecompiler/jump_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bitflags! {

impl Default for JumpControlInfoFlags {
fn default() -> Self {
JumpControlInfoFlags::empty()
Self::empty()
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Debug for JobCallback {
impl JobCallback {
/// Creates a new `JobCallback`.
pub fn new<T: Any + Trace>(callback: JsFunction, host_defined: T) -> Self {
JobCallback {
Self {
callback,
host_defined: Box::new(host_defined),
}
Expand Down
Loading

0 comments on commit e6a1c37

Please sign in to comment.