Satisfy clippy.

This commit is contained in:
Stephen Chung
2022-12-22 17:34:58 +08:00
parent bbd94dbffb
commit 80ccd75514
40 changed files with 346 additions and 196 deletions

View File

@@ -71,11 +71,13 @@ fn is_numeric(type_id: TypeId) -> bool {
/// A function that returns `true`.
#[inline(always)]
#[allow(clippy::unnecessary_wraps)]
fn const_true_fn(_: Option<NativeCallContext>, _: &mut [&mut Dynamic]) -> RhaiResult {
Ok(Dynamic::TRUE)
}
/// A function that returns `false`.
#[inline(always)]
#[allow(clippy::unnecessary_wraps)]
fn const_false_fn(_: Option<NativeCallContext>, _: &mut [&mut Dynamic]) -> RhaiResult {
Ok(Dynamic::FALSE)
}

View File

@@ -182,7 +182,7 @@ impl Engine {
match cache.map.entry(hash) {
Entry::Occupied(entry) => entry.into_mut().as_ref(),
Entry::Vacant(entry) => {
let num_args = args.as_deref().map_or(0, |a| a.len());
let num_args = args.as_deref().map_or(0, FnCallArgs::len);
let mut max_bitmask = 0; // One above maximum bitmask based on number of parameters.
// Set later when a specific matching function is not found.
let mut bitmask = 1usize; // Bitmask of which parameter to replace with `Dynamic`
@@ -1167,12 +1167,12 @@ impl Engine {
.as_int()
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, arg_pos))?;
return Ok(if !(0..=crate::MAX_USIZE_INT).contains(&num_params) {
false
} else {
#[allow(clippy::cast_sign_loss)]
return Ok(if (0..=crate::MAX_USIZE_INT).contains(&num_params) {
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
let hash_script = calc_fn_hash(None, &fn_name, num_params as usize);
self.has_script_fn(global, caches, hash_script)
} else {
false
}
.into());
}
@@ -1588,7 +1588,7 @@ impl Engine {
.0
.flatten();
return value.as_bool().and_then(|r| Ok((!r).into())).or_else(|_| {
return value.as_bool().map(|r| (!r).into()).or_else(|_| {
let operand = &mut [&mut value];
self.exec_fn_call(
global, caches, None, name, op_token, *hashes, operand, false, false, pos,

View File

@@ -201,7 +201,7 @@ impl<'a> NativeCallContext<'a> {
pub fn store_data(&self) -> NativeCallContextStore {
NativeCallContextStore {
fn_name: self.fn_name.to_string(),
source: self.source.map(|s| s.to_string()),
source: self.source.map(ToString::to_string),
global: self.global.clone(),
pos: self.pos,
}

View File

@@ -39,7 +39,6 @@ pub struct Mut<T>(T);
/// Dereference into [`DynamicWriteLock`]
#[inline(always)]
#[must_use]
pub fn by_ref<T: Variant + Clone>(data: &mut Dynamic) -> DynamicWriteLock<T> {
// Directly cast the &mut Dynamic into DynamicWriteLock to access the underlying data.
data.write_lock::<T>().expect("checked")

View File

@@ -134,7 +134,6 @@ impl Engine {
fn_def.name.to_string(),
#[cfg(not(feature = "no_module"))]
_environ
.as_deref()
.and_then(|environ| environ.lib.id())
.unwrap_or_else(|| global.source().unwrap_or(""))
.to_string(),