Skip to content

Commit

Permalink
Fix rust 1.75 lints (#3540)
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Dec 29, 2023
1 parent 1ef04a7 commit 6ac435f
Show file tree
Hide file tree
Showing 34 changed files with 134 additions and 130 deletions.
4 changes: 2 additions & 2 deletions cli/src/debug/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult<Direction> {

/// Get functions instruction flowgraph
fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
.into());
Expand Down Expand Up @@ -100,7 +100,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu
}

fn bytecode(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
.into());
Expand Down
2 changes: 1 addition & 1 deletion cli/src/debug/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use boa_engine::{

/// Returns objects pointer in memory.
fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected object argument")
.into());
Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)? {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl BuiltInConstructor for Boolean {
context: &mut Context,
) -> JsResult<JsValue> {
// 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));
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
1 change: 1 addition & 0 deletions core/engine/src/builtins/intl/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/intl/date_time_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/builtins/iterable/async_from_sync_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 »).
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Json {
pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let jsonString be ? ToString(text).
let json_string = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_string(context)?
Expand Down
8 changes: 4 additions & 4 deletions core/engine/src/builtins/number/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue> {
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 {
Expand Down Expand Up @@ -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<JsValue> {
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 {
Expand Down Expand Up @@ -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<JsValue> {
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)?;

Expand Down Expand Up @@ -252,7 +252,7 @@ pub(crate) fn parse_float(
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
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);
Expand Down
12 changes: 6 additions & 6 deletions core/engine/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl BuiltInConstructor for Number {
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
let data = match args.get(0) {
let data = match args.first() {
Some(value) => value.to_numeric_number(context)?,
None => 0.0,
};
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Number {
) -> JsResult<JsValue> {
// 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)?),
Expand Down Expand Up @@ -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,
Expand All @@ -771,7 +771,7 @@ impl Number {
args: &[JsValue],
_ctx: &mut Context,
) -> JsResult<JsValue> {
Ok(args.get(0).map_or(false, Self::is_integer).into())
Ok(args.first().map_or(false, Self::is_integer).into())
}

/// `Number.isNaN( number )`
Expand All @@ -795,7 +795,7 @@ impl Number {
_ctx: &mut Context,
) -> JsResult<JsValue> {
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
Expand Down Expand Up @@ -823,7 +823,7 @@ impl Number {
args: &[JsValue],
_ctx: &mut Context,
) -> JsResult<JsValue> {
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
Expand Down
10 changes: 5 additions & 5 deletions core/engine/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?
Expand Down Expand Up @@ -945,7 +945,7 @@ impl OrdinaryObject {
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
let Some(key) = args.get(0) else {
let Some(key) = args.first() else {
return Ok(JsValue::new(false));
};

Expand Down Expand Up @@ -1030,7 +1030,7 @@ impl OrdinaryObject {
pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;
Expand All @@ -1055,7 +1055,7 @@ impl OrdinaryObject {
pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;
Expand Down Expand Up @@ -1084,7 +1084,7 @@ impl OrdinaryObject {
pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;
Expand Down
22 changes: 11 additions & 11 deletions core/engine/src/builtins/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue> {
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);
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
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)?;
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
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)?;
Expand All @@ -209,7 +209,7 @@ impl Reflect {
pub(crate) fn get(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 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).
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
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
Expand All @@ -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<JsValue> {
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
Expand All @@ -312,7 +312,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
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
Expand All @@ -334,7 +334,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;

Expand All @@ -361,7 +361,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;

Expand All @@ -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<JsValue> {
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)?;
Expand Down Expand Up @@ -414,7 +414,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl BuiltInConstructor for String {
) -> JsResult<JsValue> {
// 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() => {
Expand Down

0 comments on commit 6ac435f

Please sign in to comment.