Skip to content

Commit 456da49

Browse files
committed
Fixing build for changes in clippy for Rust 1.61 (#2082)
This fixes the CI after the upgrade to Rust 1.61. I had to "allow" the `use_self` lint, due to rust-lang/rust-clippy#8845 and rust-lang/rust-clippy#6902. It removed some false negatives, though, so I fixed some of the usage.
1 parent f3db18f commit 456da49

File tree

10 files changed

+389
-403
lines changed

10 files changed

+389
-403
lines changed

boa_engine/src/builtins/intl/tests.rs

+24-36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn best_avail_loc() {
2828
);
2929

3030
let locale_part = "fr".to_string();
31-
let no_extensions_locale = JsString::new(locale_part.clone() + &"-CA".to_string());
31+
let no_extensions_locale = JsString::new(locale_part.clone() + "-CA");
3232
let available_locales = vec![JsString::new(locale_part.clone())];
3333
assert_eq!(
3434
best_available_locale(&available_locales, &no_extensions_locale,),
@@ -38,7 +38,7 @@ fn best_avail_loc() {
3838
let ja_kana_t = JsString::new("ja-Kana-JP-t");
3939
let ja_kana = JsString::new("ja-Kana-JP");
4040
let no_extensions_locale = JsString::new("ja-Kana-JP-t-it-latn-it");
41-
let available_locales = vec![ja_kana_t.clone(), ja_kana.clone()];
41+
let available_locales = vec![ja_kana_t, ja_kana.clone()];
4242
assert_eq!(
4343
best_available_locale(&available_locales, &no_extensions_locale,),
4444
Some(ja_kana)
@@ -108,7 +108,7 @@ fn insert_unicode_ext() {
108108
fn uni_ext_comp() {
109109
let ext = JsString::new("-u-ca-japanese-hc-h12");
110110
let components = unicode_extension_components(&ext);
111-
assert_eq!(components.attributes.is_empty(), true);
111+
assert!(components.attributes.is_empty());
112112
assert_eq!(components.keywords.len(), 2);
113113
assert_eq!(components.keywords[0].key, "ca");
114114
assert_eq!(components.keywords[0].value, "japanese");
@@ -126,7 +126,7 @@ fn uni_ext_comp() {
126126

127127
let ext = JsString::new("-u-ca-buddhist-kk-nu-thai");
128128
let components = unicode_extension_components(&ext);
129-
assert_eq!(components.attributes.is_empty(), true);
129+
assert!(components.attributes.is_empty());
130130
assert_eq!(components.keywords.len(), 3);
131131
assert_eq!(components.keywords[0].key, "ca");
132132
assert_eq!(components.keywords[0].value, "buddhist");
@@ -137,7 +137,7 @@ fn uni_ext_comp() {
137137

138138
let ext = JsString::new("-u-ca-islamic-civil");
139139
let components = unicode_extension_components(&ext);
140-
assert_eq!(components.attributes.is_empty(), true);
140+
assert!(components.attributes.is_empty());
141141
assert_eq!(components.keywords.len(), 1);
142142
assert_eq!(components.keywords[0].key, "ca");
143143
assert_eq!(components.keywords[0].value, "islamic-civil");
@@ -167,7 +167,7 @@ fn locale_resolution() {
167167
);
168168
assert_eq!(locale_record.locale, default_locale());
169169
assert_eq!(locale_record.data_locale, default_locale());
170-
assert_eq!(locale_record.properties.is_empty(), true);
170+
assert!(locale_record.properties.is_empty());
171171

172172
// test best fit
173173
let available_locales = Vec::<JsString>::new();
@@ -189,7 +189,7 @@ fn locale_resolution() {
189189
);
190190
assert_eq!(locale_record.locale, default_locale());
191191
assert_eq!(locale_record.data_locale, default_locale());
192-
assert_eq!(locale_record.properties.is_empty(), true);
192+
assert!(locale_record.properties.is_empty());
193193

194194
// available: [es-ES], requested: [es-ES]
195195
let available_locales = vec![JsString::new("es-ES")];
@@ -211,7 +211,7 @@ fn locale_resolution() {
211211
);
212212
assert_eq!(locale_record.locale, "es-ES");
213213
assert_eq!(locale_record.data_locale, "es-ES");
214-
assert_eq!(locale_record.properties.is_empty(), true);
214+
assert!(locale_record.properties.is_empty());
215215

216216
// available: [zh-CN], requested: []
217217
let available_locales = vec![JsString::new("zh-CN")];
@@ -233,7 +233,7 @@ fn locale_resolution() {
233233
);
234234
assert_eq!(locale_record.locale, default_locale());
235235
assert_eq!(locale_record.data_locale, default_locale());
236-
assert_eq!(locale_record.properties.is_empty(), true);
236+
assert!(locale_record.properties.is_empty());
237237
}
238238

239239
#[test]
@@ -319,7 +319,7 @@ fn get_opt() {
319319
let other_locale_str = JsString::new("de-DE");
320320
let values = vec![other_locale_str];
321321
options_obj
322-
.set("Locale", locale_value.clone(), true, &mut context)
322+
.set("Locale", locale_value, true, &mut context)
323323
.expect("Setting a property should not fail");
324324
let option_type = GetOptionType::String;
325325
let get_option_result = get_option(
@@ -330,7 +330,7 @@ fn get_opt() {
330330
&fallback,
331331
&mut context,
332332
);
333-
assert_eq!(get_option_result.is_err(), true);
333+
assert!(get_option_result.is_err());
334334

335335
let value = JsValue::undefined();
336336
let minimum = 1.0;
@@ -345,21 +345,21 @@ fn get_opt() {
345345
let maximum = 10.0;
346346
let fallback = Some(5.0);
347347
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
348-
assert_eq!(get_option_result.is_err(), true);
348+
assert!(get_option_result.is_err());
349349

350350
let value = JsValue::new(0);
351351
let minimum = 1.0;
352352
let maximum = 10.0;
353353
let fallback = Some(5.0);
354354
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
355-
assert_eq!(get_option_result.is_err(), true);
355+
assert!(get_option_result.is_err());
356356

357357
let value = JsValue::new(11);
358358
let minimum = 1.0;
359359
let maximum = 10.0;
360360
let fallback = Some(5.0);
361361
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
362-
assert_eq!(get_option_result.is_err(), true);
362+
assert!(get_option_result.is_err());
363363

364364
let value_f64 = 7.0;
365365
let value = JsValue::new(value_f64);
@@ -375,34 +375,22 @@ fn get_opt() {
375375
let maximum = 10.0;
376376
let fallback_val = 5.0;
377377
let fallback = Some(fallback_val);
378-
let get_option_result = get_number_option(
379-
&options,
380-
&property,
381-
minimum,
382-
maximum,
383-
fallback,
384-
&mut context,
385-
);
378+
let get_option_result =
379+
get_number_option(&options, property, minimum, maximum, fallback, &mut context);
386380
assert_eq!(get_option_result, Ok(fallback));
387381

388382
let options = JsObject::empty();
389383
let value_f64 = 8.0;
390384
let value = JsValue::new(value_f64);
391385
let property = "fractionalSecondDigits";
392386
options
393-
.set(property, value.clone(), true, &mut context)
387+
.set(property, value, true, &mut context)
394388
.expect("Setting a property should not fail");
395389
let minimum = 1.0;
396390
let maximum = 10.0;
397391
let fallback = Some(5.0);
398-
let get_option_result = get_number_option(
399-
&options,
400-
&property,
401-
minimum,
402-
maximum,
403-
fallback,
404-
&mut context,
405-
);
392+
let get_option_result =
393+
get_number_option(&options, property, minimum, maximum, fallback, &mut context);
406394
assert_eq!(get_option_result, Ok(Some(value_f64)));
407395
}
408396

@@ -420,7 +408,7 @@ fn to_date_time_opts() {
420408
&DateTimeReqs::Date,
421409
&mut context,
422410
);
423-
assert_eq!(date_time_opts.is_err(), true);
411+
assert!(date_time_opts.is_err());
424412

425413
let options_obj = JsObject::empty();
426414
options_obj
@@ -432,7 +420,7 @@ fn to_date_time_opts() {
432420
&DateTimeReqs::Time,
433421
&mut context,
434422
);
435-
assert_eq!(date_time_opts.is_err(), true);
423+
assert!(date_time_opts.is_err());
436424

437425
let date_time_opts = to_date_time_options(
438426
&JsValue::undefined(),
@@ -453,7 +441,7 @@ fn to_date_time_opts() {
453441
);
454442
assert_eq!(
455443
date_time_opts.get("day", &mut context),
456-
Ok(numeric_jsstring.clone())
444+
Ok(numeric_jsstring)
457445
);
458446

459447
let date_time_opts = to_date_time_options(
@@ -475,7 +463,7 @@ fn to_date_time_opts() {
475463
);
476464
assert_eq!(
477465
date_time_opts.get("second", &mut context),
478-
Ok(numeric_jsstring.clone())
466+
Ok(numeric_jsstring)
479467
);
480468

481469
let date_time_opts = to_date_time_options(
@@ -509,6 +497,6 @@ fn to_date_time_opts() {
509497
);
510498
assert_eq!(
511499
date_time_opts.get("second", &mut context),
512-
Ok(numeric_jsstring.clone())
500+
Ok(numeric_jsstring)
513501
);
514502
}

boa_engine/src/builtins/typed_array/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -3438,22 +3438,22 @@ impl TypedArrayKind {
34383438
#[inline]
34393439
pub(crate) const fn name(&self) -> &str {
34403440
match self {
3441-
TypedArrayKind::Int8 => "Int8Array",
3442-
TypedArrayKind::Uint8 => "Uint8Array",
3443-
TypedArrayKind::Uint8Clamped => "Uint8ClampedArray",
3444-
TypedArrayKind::Int16 => "Int16Array",
3445-
TypedArrayKind::Uint16 => "Uint16Array",
3446-
TypedArrayKind::Int32 => "Int32Array",
3447-
TypedArrayKind::Uint32 => "Uint32Array",
3448-
TypedArrayKind::BigInt64 => "BigInt64Array",
3449-
TypedArrayKind::BigUint64 => "BigUint64Array",
3450-
TypedArrayKind::Float32 => "Float32Array",
3451-
TypedArrayKind::Float64 => "Float64Array",
3441+
Self::Int8 => "Int8Array",
3442+
Self::Uint8 => "Uint8Array",
3443+
Self::Uint8Clamped => "Uint8ClampedArray",
3444+
Self::Int16 => "Int16Array",
3445+
Self::Uint16 => "Uint16Array",
3446+
Self::Int32 => "Int32Array",
3447+
Self::Uint32 => "Uint32Array",
3448+
Self::BigInt64 => "BigInt64Array",
3449+
Self::BigUint64 => "BigUint64Array",
3450+
Self::Float32 => "Float32Array",
3451+
Self::Float64 => "Float64Array",
34523452
}
34533453
}
34543454

34553455
pub(crate) fn is_big_int_element_type(self) -> bool {
3456-
matches!(self, TypedArrayKind::BigUint64 | TypedArrayKind::BigInt64)
3456+
matches!(self, Self::BigUint64 | Self::BigInt64)
34573457
}
34583458
}
34593459

boa_engine/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
clippy::all,
2727
clippy::cast_lossless,
2828
clippy::redundant_closure_for_method_calls,
29-
clippy::use_self,
3029
clippy::unnested_or_patterns,
3130
clippy::trivially_copy_pass_by_ref,
3231
clippy::needless_pass_by_value,
@@ -49,6 +48,7 @@
4948
nonstandard_style,
5049
)]
5150
#![allow(
51+
clippy::use_self, // TODO: deny once false positives are fixed
5252
clippy::module_name_repetitions,
5353
clippy::cast_possible_truncation,
5454
clippy::cast_sign_loss,
@@ -99,7 +99,6 @@ pub use crate::{
9999
};
100100

101101
/// The result of a Javascript expression is represented like this so it can succeed (`Ok`) or fail (`Err`)
102-
#[must_use]
103102
pub type JsResult<T> = StdResult<T, JsValue>;
104103

105104
/// Execute the code using an existing `Context`.

boa_engine/src/syntax/ast/keyword.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ impl Keyword {
485485
/// Gets the keyword as a binary operation, if this keyword is the `in` keyword.
486486
pub fn as_binop(self) -> Option<BinOp> {
487487
match self {
488-
Keyword::In => Some(BinOp::Comp(CompOp::In)),
489-
Keyword::InstanceOf => Some(BinOp::Comp(CompOp::InstanceOf)),
488+
Self::In => Some(BinOp::Comp(CompOp::In)),
489+
Self::InstanceOf => Some(BinOp::Comp(CompOp::InstanceOf)),
490490
_ => None,
491491
}
492492
}

boa_engine/src/syntax/ast/node/declaration/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ pub enum BindingPatternTypeObject {
546546
impl ToInternedString for BindingPatternTypeObject {
547547
fn to_interned_string(&self, interner: &Interner) -> String {
548548
match self {
549-
BindingPatternTypeObject::Empty => String::new(),
550-
BindingPatternTypeObject::SingleName {
549+
Self::Empty => String::new(),
550+
Self::SingleName {
551551
ident,
552552
property_name,
553553
default_init,
@@ -576,18 +576,18 @@ impl ToInternedString for BindingPatternTypeObject {
576576
}
577577
buf
578578
}
579-
BindingPatternTypeObject::RestProperty {
579+
Self::RestProperty {
580580
ident: property_name,
581581
excluded_keys: _,
582582
} => {
583583
format!(" ... {}", interner.resolve_expect(*property_name))
584584
}
585-
BindingPatternTypeObject::RestGetConstField {
585+
Self::RestGetConstField {
586586
get_const_field, ..
587587
} => {
588588
format!(" ... {}", get_const_field.to_interned_string(interner))
589589
}
590-
BindingPatternTypeObject::BindingPattern {
590+
Self::BindingPattern {
591591
ident: property_name,
592592
pattern,
593593
default_init,
@@ -733,9 +733,9 @@ pub enum BindingPatternTypeArray {
733733
impl ToInternedString for BindingPatternTypeArray {
734734
fn to_interned_string(&self, interner: &Interner) -> String {
735735
match self {
736-
BindingPatternTypeArray::Empty => String::new(),
737-
BindingPatternTypeArray::Elision => " ".to_owned(),
738-
BindingPatternTypeArray::SingleName {
736+
Self::Empty => String::new(),
737+
Self::Elision => " ".to_owned(),
738+
Self::SingleName {
739739
ident,
740740
default_init,
741741
} => {
@@ -745,25 +745,25 @@ impl ToInternedString for BindingPatternTypeArray {
745745
}
746746
buf
747747
}
748-
BindingPatternTypeArray::GetField { get_field } => {
748+
Self::GetField { get_field } => {
749749
format!(" {}", get_field.to_interned_string(interner))
750750
}
751-
BindingPatternTypeArray::GetConstField { get_const_field } => {
751+
Self::GetConstField { get_const_field } => {
752752
format!(" {}", get_const_field.to_interned_string(interner))
753753
}
754-
BindingPatternTypeArray::BindingPattern { pattern } => {
754+
Self::BindingPattern { pattern } => {
755755
format!(" {}", pattern.to_interned_string(interner))
756756
}
757-
BindingPatternTypeArray::SingleNameRest { ident } => {
757+
Self::SingleNameRest { ident } => {
758758
format!(" ... {}", interner.resolve_expect(*ident))
759759
}
760-
BindingPatternTypeArray::GetFieldRest { get_field } => {
760+
Self::GetFieldRest { get_field } => {
761761
format!(" ... {}", get_field.to_interned_string(interner))
762762
}
763-
BindingPatternTypeArray::GetConstFieldRest { get_const_field } => {
763+
Self::GetConstFieldRest { get_const_field } => {
764764
format!(" ... {}", get_const_field.to_interned_string(interner))
765765
}
766-
BindingPatternTypeArray::BindingPatternRest { pattern } => {
766+
Self::BindingPatternRest { pattern } => {
767767
format!(" ... {}", pattern.to_interned_string(interner))
768768
}
769769
}

boa_engine/src/value/equality.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ impl JsValue {
189189
fn same_value_non_numeric(x: &Self, y: &Self) -> bool {
190190
debug_assert!(x.get_type() == y.get_type());
191191
match (x, y) {
192-
(JsValue::Null, JsValue::Null) | (JsValue::Undefined, JsValue::Undefined) => true,
193-
(JsValue::String(ref x), JsValue::String(ref y)) => x == y,
194-
(JsValue::Boolean(x), JsValue::Boolean(y)) => x == y,
195-
(JsValue::Object(ref x), JsValue::Object(ref y)) => JsObject::equals(x, y),
196-
(JsValue::Symbol(ref x), JsValue::Symbol(ref y)) => x == y,
192+
(Self::Null, Self::Null) | (Self::Undefined, Self::Undefined) => true,
193+
(Self::String(ref x), Self::String(ref y)) => x == y,
194+
(Self::Boolean(x), Self::Boolean(y)) => x == y,
195+
(Self::Object(ref x), Self::Object(ref y)) => JsObject::equals(x, y),
196+
(Self::Symbol(ref x), Self::Symbol(ref y)) => x == y,
197197
_ => false,
198198
}
199199
}

0 commit comments

Comments
 (0)