Merge pull request #688 from Mathieu-Lala/fix/lint

Fix lints warnings and enhance the CI
This commit is contained in:
Stephen Chung
2023-02-10 18:32:14 +08:00
committed by GitHub
41 changed files with 204 additions and 194 deletions

View File

@@ -212,12 +212,12 @@ impl Engine {
}
/// Evaluate an [`AST`] with own scope, returning the result value or an error.
#[inline]
pub(crate) fn eval_ast_with_scope_raw<'a>(
pub(crate) fn eval_ast_with_scope_raw(
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
scope: &mut Scope,
ast: &'a AST,
ast: &AST,
) -> RhaiResult {
let orig_source = mem::replace(&mut global.source, ast.source_raw().cloned());
@@ -245,16 +245,16 @@ impl Engine {
g.source = orig_source;
});
self.eval_global_statements(global, caches, scope, ast.statements())
.and_then(|r| {
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
}
Ok(r)
})
let r = self.eval_global_statements(global, caches, scope, ast.statements())?;
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
}
Ok(r)
}
}

View File

@@ -97,7 +97,7 @@ impl Engine {
///
/// // Compile a script to an AST and store it for later evaluation.
/// // Notice that a PathBuf is required which can easily be constructed from a string.
/// let ast = engine.compile_file_with_scope(&mut scope, "script.rhai".into())?;
/// let ast = engine.compile_file_with_scope(&scope, "script.rhai".into())?;
///
/// let result = engine.eval_ast::<i64>(&ast)?;
/// # }

View File

@@ -126,16 +126,16 @@ impl Engine {
global.embedded_module_resolver = ast.resolver().cloned();
}
self.eval_global_statements(global, caches, scope, ast.statements())
.and_then(|_| {
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(crate::Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
}
Ok(())
})
let _ = self.eval_global_statements(global, caches, scope, ast.statements())?;
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(crate::Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
}
Ok(())
}
}

View File

@@ -103,11 +103,11 @@ impl Dynamic {
pub(crate) fn calc_data_sizes(&self, _top: bool) -> (usize, usize, usize) {
match self.0 {
#[cfg(not(feature = "no_index"))]
Union::Array(ref arr, ..) => Self::calc_array_sizes(&**arr),
Union::Array(ref arr, ..) => Self::calc_array_sizes(arr),
#[cfg(not(feature = "no_index"))]
Union::Blob(ref blob, ..) => (blob.len(), 0, 0),
#[cfg(not(feature = "no_object"))]
Union::Map(ref map, ..) => Self::calc_map_sizes(&**map),
Union::Map(ref map, ..) => Self::calc_map_sizes(map),
Union::Str(ref s, ..) => (0, 0, s.len()),
#[cfg(not(feature = "no_closure"))]
Union::Shared(..) if _top => self.read_lock::<Self>().unwrap().calc_data_sizes(true),

View File

@@ -42,7 +42,7 @@
//!
//! # #[cfg(not(feature = "no_std"))]
//! # #[cfg(not(target_family = "wasm"))]
//! #
//! #
//! // Evaluate the script, expecting a 'bool' result
//! let result: bool = engine.eval_file("my_script.rhai".into())?;
//!
@@ -82,8 +82,8 @@
// The lints below can be turned off to reduce signal/noise ratio
// #![allow(clippy::too_many_lines)]
// #![allow(clippy::let_underscore_drop)]
// #![allow(clippy::absurd_extreme_comparisons)]
// #![allow(clippy::unnecessary_cast)]
#![allow(clippy::absurd_extreme_comparisons)]
#![allow(clippy::unnecessary_cast)]
// #![allow(clippy::wildcard_imports)]
#[cfg(feature = "no_std")]
@@ -166,8 +166,7 @@ const MAX_USIZE_INT: INT = INT::MAX;
const MAX_USIZE_INT: INT = usize::MAX as INT;
/// The maximum integer that can fit into a [`usize`].
#[cfg(feature = "only_i32")]
#[cfg(target_pointer_width = "32")]
#[cfg(all(feature = "only_i32", target_pointer_width = "32"))]
const MAX_USIZE_INT: INT = INT::MAX;
/// Number of bits in [`INT`].
@@ -316,8 +315,7 @@ pub type OptimizationLevel = ();
#[cfg(feature = "internals")]
pub use types::dynamic::{AccessMode, DynamicReadLock, DynamicWriteLock, Variant};
#[cfg(feature = "internals")]
#[cfg(not(feature = "no_float"))]
#[cfg(all(feature = "internals", not(feature = "no_float")))]
pub use types::FloatWrapper;
#[cfg(feature = "internals")]

View File

@@ -140,15 +140,15 @@ mod print_debug_functions {
}
/// Return the empty string.
#[allow(unused_variables)]
#[rhai_fn(name = "print", name = "to_string")]
pub fn print_unit(ctx: NativeCallContext, unit: ()) -> ImmutableString {
let _ = unit;
ctx.engine().const_empty_string()
}
/// Convert the unit into a string in debug format.
#[allow(unused_variables)]
#[rhai_fn(name = "debug", name = "to_debug")]
pub fn debug_unit(unit: ()) -> ImmutableString {
let _ = unit;
"()".into()
}

View File

@@ -83,13 +83,14 @@ mod string_functions {
buf.into()
}
#[allow(unused_variables)]
#[rhai_fn(name = "+")]
pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString {
let _ = item;
string
}
#[allow(unused_variables)]
#[rhai_fn(name = "+")]
pub fn add_prepend_unit(_item: (), string: ImmutableString) -> ImmutableString {
pub fn add_prepend_unit(item: (), string: ImmutableString) -> ImmutableString {
string
}
@@ -101,11 +102,9 @@ mod string_functions {
pub fn add_assign_append_char(string: &mut ImmutableString, character: char) {
*string += character;
}
#[allow(unused_variables)]
#[rhai_fn(name = "+=")]
pub fn add_assign_append_unit(string: &mut ImmutableString, item: ()) {
let _ = string;
let _ = item;
}
pub fn add_assign_append_unit(string: &mut ImmutableString, item: ()) {}
#[cfg(not(feature = "no_index"))]
pub mod blob_functions {

View File

@@ -155,7 +155,9 @@ mod time_functions {
})
}
} else {
Ok(timestamp - Duration::from_millis((seconds * 1000.0) as u64))
Ok(timestamp
.checked_sub(Duration::from_millis((seconds * 1000.0) as u64))
.unwrap())
}
}
@@ -212,7 +214,9 @@ mod time_functions {
))
})
} else {
Ok(timestamp - Duration::from_secs(seconds as u64))
Ok(timestamp
.checked_sub(Duration::from_secs(seconds as u64))
.unwrap())
}
}

View File

@@ -1203,7 +1203,7 @@ const fn is_hex_digit(c: char) -> bool {
/// Test if the given character is a numeric digit.
#[inline(always)]
const fn is_numeric_digit(c: char) -> bool {
matches!(c, '0'..='9')
c.is_ascii_digit()
}
/// Test if the comment block is a doc-comment.