Clean up clippy.

This commit is contained in:
Stephen Chung
2022-07-27 16:04:24 +08:00
parent 21f822020f
commit 39dee556c4
36 changed files with 271 additions and 369 deletions

View File

@@ -453,7 +453,7 @@ impl Engine {
// Check the data size of any `&mut` object, which may be changed.
#[cfg(not(feature = "unchecked"))]
if is_ref_mut && args.len() > 0 {
if is_ref_mut && !args.is_empty() {
self.check_data_size(args[0], pos)?;
}
@@ -1180,7 +1180,7 @@ impl Engine {
if capture_scope && !scope.is_empty() {
first_arg
.iter()
.map(|&v| v)
.copied()
.chain(a_expr.iter())
.try_for_each(|expr| {
self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level)

View File

@@ -173,10 +173,10 @@ pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
pub fn calc_fn_params_hash(params: impl IntoIterator<Item = TypeId>) -> u64 {
let s = &mut get_hasher();
let mut len = 0;
params
.into_iter()
.inspect(|_| len += 1)
.for_each(|t| t.hash(s));
params.into_iter().for_each(|t| {
len += 1;
t.hash(s)
});
len.hash(s);
match s.finish() {

View File

@@ -37,17 +37,14 @@ pub use std::sync::Arc as Shared;
/// Synchronized shared object.
#[cfg(not(feature = "sync"))]
#[allow(dead_code)]
pub use std::cell::RefCell as Locked;
/// Read-only lock guard for synchronized shared object.
#[cfg(not(feature = "sync"))]
#[allow(dead_code)]
pub type LockGuard<'a, T> = std::cell::Ref<'a, T>;
/// Mutable lock guard for synchronized shared object.
#[cfg(not(feature = "sync"))]
#[allow(dead_code)]
pub type LockGuardMut<'a, T> = std::cell::RefMut<'a, T>;
/// Synchronized shared object.
@@ -397,7 +394,7 @@ pub fn shared_take<T>(value: Shared<T>) -> T {
#[inline(always)]
#[must_use]
#[allow(dead_code)]
pub fn locked_read<'a, T>(value: &'a Locked<T>) -> LockGuard<'a, T> {
pub fn locked_read<T>(value: &Locked<T>) -> LockGuard<T> {
#[cfg(not(feature = "sync"))]
return value.borrow();
@@ -409,7 +406,7 @@ pub fn locked_read<'a, T>(value: &'a Locked<T>) -> LockGuard<'a, T> {
#[inline(always)]
#[must_use]
#[allow(dead_code)]
pub fn locked_write<'a, T>(value: &'a Locked<T>) -> LockGuardMut<'a, T> {
pub fn locked_write<T>(value: &Locked<T>) -> LockGuardMut<T> {
#[cfg(not(feature = "sync"))]
return value.borrow_mut();

View File

@@ -56,7 +56,7 @@ pub fn by_value<T: Variant + Clone>(data: &mut Dynamic) -> T {
// We consume the argument and then replace it with () - the argument is not supposed to be used again.
// This way, we avoid having to clone the argument again, because it is already a clone when passed here.
return mem::take(data).cast::<T>();
mem::take(data).cast::<T>()
}
/// Trait to register custom Rust functions.

View File

@@ -88,7 +88,7 @@ impl Engine {
let orig_call_stack_len = global.debugger.call_stack().len();
// Put arguments into scope as variables
scope.extend(fn_def.params.iter().cloned().zip(args.into_iter().map(|v| {
scope.extend(fn_def.params.iter().cloned().zip(args.iter_mut().map(|v| {
// Actually consume the arguments instead of cloning them
mem::take(*v)
})));
@@ -98,11 +98,7 @@ impl Engine {
if self.debugger.is_some() {
global.debugger.push_call_stack_frame(
fn_def.name.clone(),
scope
.iter()
.skip(orig_scope_len)
.map(|(.., v)| v.clone())
.collect(),
scope.iter().skip(orig_scope_len).map(|(.., v)| v).collect(),
global.source.clone(),
pos,
);