Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new clippy lints for rustc 1.77 #3759

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ unused_crate_dependencies = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"

[workspace.lints.rustdoc]
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ fn main() -> Result<(), io::Error> {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(CLI_HISTORY)?;
editor.load_history(CLI_HISTORY).map_err(|err| match err {
ReadlineError::Io(e) => e,
Expand Down
3 changes: 1 addition & 2 deletions core/engine/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ impl ArrayBuffer {
Ok(args
.get_or_undefined(0)
.as_object()
.map(|obj| obj.is::<TypedArray>() || obj.is::<DataView>())
.unwrap_or_default()
.is_some_and(|obj| obj.is::<TypedArray>() || obj.is::<DataView>())
.into())
}

Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/number/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub(crate) fn parse_int(_: &JsValue, args: &[JsValue], context: &mut Context) ->
// 11. If S contains a code unit that is not a radix-R digit, let end be the index within S of the
// first such code unit; otherwise, let end be the length of S.
let end = char::decode_utf16(var_s.iter().copied())
.position(|code| !code.map(|c| c.is_digit(var_r as u32)).unwrap_or_default())
.position(|code| !code.is_ok_and(|c| c.is_digit(var_r as u32)))
.unwrap_or(var_s.len());

// 12. Let Z be the substring of S from 0 to end.
Expand Down
1 change: 0 additions & 1 deletion core/engine/src/builtins/typed_array/element/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(clippy::cast_ptr_alignment)] // Invariants are checked by the caller.
#![allow(unused_tuple_struct_fields)] // Weird false-positive with `boa_macros_tests`

mod atomic;

Expand Down
9 changes: 3 additions & 6 deletions core/engine/src/builtins/typed_array/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,9 @@ fn typed_array_get_element(obj: &JsObject, index: f64) -> Option<JsValue> {
let buffer = buffer.as_buffer();

// 1. If IsValidIntegerIndex(O, index) is false, return undefined.
let Some(buffer) = buffer.bytes(Ordering::Relaxed) else {
return None;
};
let Some(index) = inner.validate_index(index, buffer.len()) else {
return None;
};
let buffer = buffer.bytes(Ordering::Relaxed)?;

let index = inner.validate_index(index, buffer.len())?;

// 2. Let offset be O.[[ByteOffset]].
let offset = inner.byte_offset();
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::vm::RuntimeLimits;
use self::intrinsics::StandardConstructor;

thread_local! {
static CANNOT_BLOCK_COUNTER: Cell<u64> = Cell::new(0);
static CANNOT_BLOCK_COUNTER: Cell<u64> = const { Cell::new(0) };
}

/// ECMAScript context. It is the primary way to interact with the runtime.
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/module/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl SourceTextModule {
/// Returns an error if there's no more available indices.
fn get_async_eval_index() -> JsResult<usize> {
thread_local! {
static ASYNC_EVAL_QUEUE_INDEX: Cell<usize> = Cell::new(0);
static ASYNC_EVAL_QUEUE_INDEX: Cell<usize> = const { Cell::new(0) };
}

ASYNC_EVAL_QUEUE_INDEX
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/object/internal_methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub(crate) fn ordinary_get_prototype_of(
let _timer = Profiler::global().start_event("Object::ordinary_get_prototype_of", "object");

// 1. Return O.[[Prototype]].
Ok(obj.prototype().as_ref().cloned())
Ok(obj.prototype().clone())
}

/// Abstract operation `OrdinarySetPrototypeOf`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,14 @@ impl ForwardTransition {
/// Get a property transition, return [`None`] otherwise.
pub(super) fn get_property(&self, key: &TransitionKey) -> Option<WeakGc<SharedShapeInner>> {
let this = self.inner.borrow();
let Some(transitions) = this.properties.as_ref() else {
return None;
};
let transitions = this.properties.as_ref()?;
transitions.map.get(key).cloned()
}

/// Get a prototype transition, return [`None`] otherwise.
pub(super) fn get_prototype(&self, key: &JsPrototype) -> Option<WeakGc<SharedShapeInner>> {
let this = self.inner.borrow();
let Some(transitions) = this.prototypes.as_ref() else {
return None;
};
let transitions = this.prototypes.as_ref()?;
transitions.map.get(key).cloned()
}

Expand Down
20 changes: 10 additions & 10 deletions core/engine/src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,22 +868,22 @@ pub(crate) trait Utf16Trim {

impl Utf16Trim for [u16] {
fn trim_start(&self) -> &Self {
if let Some(left) = self.iter().copied().position(|r| {
!char::from_u32(u32::from(r))
.map(is_trimmable_whitespace)
.unwrap_or_default()
}) {
if let Some(left) = self
.iter()
.copied()
.position(|r| !char::from_u32(u32::from(r)).is_some_and(is_trimmable_whitespace))
{
&self[left..]
} else {
&[]
}
}
fn trim_end(&self) -> &Self {
if let Some(right) = self.iter().copied().rposition(|r| {
!char::from_u32(u32::from(r))
.map(is_trimmable_whitespace)
.unwrap_or_default()
}) {
if let Some(right) = self
.iter()
.copied()
.rposition(|r| !char::from_u32(u32::from(r)).is_some_and(is_trimmable_whitespace))
{
&self[..=right]
} else {
&[]
Expand Down
2 changes: 1 addition & 1 deletion core/gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type GcErasedPointer = NonNull<GcBox<NonTraceable>>;
type EphemeronPointer = NonNull<dyn ErasedEphemeronBox>;
type ErasedWeakMapBoxPointer = NonNull<dyn ErasedWeakMapBox>;

thread_local!(static GC_DROPPING: Cell<bool> = Cell::new(false));
thread_local!(static GC_DROPPING: Cell<bool> = const { Cell::new(false) });
thread_local!(static BOA_GC: RefCell<BoaGc> = RefCell::new( BoaGc {
config: GcConfig::default(),
runtime: GcRuntimeData::default(),
Expand Down
1 change: 0 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ unsafe_op_in_unsafe_fn = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"

[lints.clippy]
Expand Down
2 changes: 1 addition & 1 deletion tests/macros/tests/derive/from_js_with.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused, unused_tuple_struct_fields)]
#![allow(unused)]

use boa_engine::{value::TryFromJs, Context, JsNativeError, JsResult, JsValue};

Expand Down
2 changes: 1 addition & 1 deletion tests/macros/tests/derive/simple_struct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused, unused_tuple_struct_fields)]
#![allow(unused)]

use boa_engine::value::TryFromJs;

Expand Down
2 changes: 1 addition & 1 deletion tests/macros/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused_crate_dependencies, unused_tuple_struct_fields)]
#![allow(unused_crate_dependencies)]

#[test]
fn try_from_js() {
Expand Down
3 changes: 1 addition & 2 deletions tests/tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,7 @@ fn is_error_type(error: &JsError, target_type: ErrorType, context: &mut Context)
.and_then(|o| o.get(js_string!("name"), context).ok())
.as_ref()
.and_then(JsValue::as_string)
.map(|s| s == target_type.as_str())
.unwrap_or_default();
.is_some_and(|s| s == target_type.as_str());
passed
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ impl Ignored {
feature
.split('.')
.next()
.map(|feat| self.features.contains(feat))
.unwrap_or_default()
.is_some_and(|feat| self.features.contains(feat))
}

pub(crate) const fn contains_any_flag(&self, flags: TestFlags) -> bool {
Expand Down
Loading