Satisfy clippy.
This commit is contained in:
parent
c58fe87107
commit
75718a5a8b
@ -93,7 +93,7 @@ impl OpAssignment {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new_op_assignment_from_base(name: &str, pos: Position) -> Self {
|
pub fn new_op_assignment_from_base(name: &str, pos: Position) -> Self {
|
||||||
let op = Token::lookup_symbol_from_syntax(name).expect("operator");
|
let op = Token::lookup_symbol_from_syntax(name).expect("operator");
|
||||||
Self::new_op_assignment_from_base_token(op, pos)
|
Self::new_op_assignment_from_base_token(&op, pos)
|
||||||
}
|
}
|
||||||
/// Convert a [`Token`] into a new [`OpAssignment`].
|
/// Convert a [`Token`] into a new [`OpAssignment`].
|
||||||
///
|
///
|
||||||
@ -102,7 +102,7 @@ impl OpAssignment {
|
|||||||
/// Panics if the token is cannot be converted into an op-assignment operator.
|
/// Panics if the token is cannot be converted into an op-assignment operator.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new_op_assignment_from_base_token(op: Token, pos: Position) -> Self {
|
pub fn new_op_assignment_from_base_token(op: &Token, pos: Position) -> Self {
|
||||||
Self::new_op_assignment_from_token(op.convert_to_op_assignment().expect("operator"), pos)
|
Self::new_op_assignment_from_token(op.convert_to_op_assignment().expect("operator"), pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +166,7 @@ fn load_script(engine: &Engine) -> (rhai::AST, String) {
|
|||||||
|
|
||||||
let filename = match Path::new(&filename).canonicalize() {
|
let filename = match Path::new(&filename).canonicalize() {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!(
|
eprintln!("\x1b[31mError script file path: {filename}\n{err}\x1b[39m");
|
||||||
"\x1b[31mError script file path: {}\n{}\x1b[39m",
|
|
||||||
filename, err
|
|
||||||
);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
@ -315,7 +312,7 @@ fn debug_callback(
|
|||||||
}
|
}
|
||||||
["node"] => {
|
["node"] => {
|
||||||
if pos.is_none() {
|
if pos.is_none() {
|
||||||
println!("{:?}", node);
|
println!("{node:?}");
|
||||||
} else {
|
} else {
|
||||||
match source {
|
match source {
|
||||||
Some(source) => println!("{node:?} {source} @ {pos:?}"),
|
Some(source) => println!("{node:?} {source} @ {pos:?}"),
|
||||||
@ -400,7 +397,7 @@ fn debug_callback(
|
|||||||
#[cfg(not(feature = "no_position"))]
|
#[cfg(not(feature = "no_position"))]
|
||||||
rhai::debugger::BreakPoint::AtPosition { pos, .. } => {
|
rhai::debugger::BreakPoint::AtPosition { pos, .. } => {
|
||||||
let line_num = format!("[{}] line ", i + 1);
|
let line_num = format!("[{}] line ", i + 1);
|
||||||
print!("{}", line_num);
|
print!("{line_num}");
|
||||||
print_source(lines, *pos, line_num.len(), (0, 0));
|
print_source(lines, *pos, line_num.len(), (0, 0));
|
||||||
}
|
}
|
||||||
_ => println!("[{}] {bp}", i + 1),
|
_ => println!("[{}] {bp}", i + 1),
|
||||||
|
@ -495,13 +495,13 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// It is up to the [`Engine`] to reactivate the debugger.
|
/// It is up to the [`Engine`] to reactivate the debugger.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn run_debugger_raw<'a>(
|
pub(crate) fn run_debugger_raw(
|
||||||
&self,
|
&self,
|
||||||
global: &mut GlobalRuntimeState,
|
global: &mut GlobalRuntimeState,
|
||||||
caches: &mut Caches,
|
caches: &mut Caches,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
this_ptr: Option<&mut Dynamic>,
|
this_ptr: Option<&mut Dynamic>,
|
||||||
node: ASTNode<'a>,
|
node: ASTNode,
|
||||||
event: DebuggerEvent,
|
event: DebuggerEvent,
|
||||||
) -> Result<Option<DebuggerStatus>, Box<crate::EvalAltResult>> {
|
) -> Result<Option<DebuggerStatus>, Box<crate::EvalAltResult>> {
|
||||||
if let Some(ref x) = self.debugger_interface {
|
if let Some(ref x) = self.debugger_interface {
|
||||||
|
@ -80,11 +80,14 @@
|
|||||||
#![allow(clippy::upper_case_acronyms)]
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
#![allow(clippy::match_same_arms)]
|
#![allow(clippy::match_same_arms)]
|
||||||
// The lints below can be turned off to reduce signal/noise ratio
|
// The lints below can be turned off to reduce signal/noise ratio
|
||||||
// #![allow(clippy::too_many_lines)]
|
#![allow(clippy::too_many_lines)]
|
||||||
// #![allow(clippy::let_underscore_drop)]
|
#![allow(clippy::let_underscore_drop)]
|
||||||
#![allow(clippy::absurd_extreme_comparisons)]
|
#![allow(clippy::absurd_extreme_comparisons)]
|
||||||
#![allow(clippy::unnecessary_cast)]
|
#![allow(clippy::unnecessary_cast)]
|
||||||
// #![allow(clippy::wildcard_imports)]
|
#![allow(clippy::wildcard_imports)]
|
||||||
|
#![allow(clippy::no_effect_underscore_binding)]
|
||||||
|
#![allow(clippy::semicolon_if_nothing_returned)]
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
@ -233,7 +233,7 @@ impl fmt::Debug for Module {
|
|||||||
.modules
|
.modules
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|m| m.keys())
|
.flat_map(BTreeMap::keys)
|
||||||
.map(SmartString::as_str)
|
.map(SmartString::as_str)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
@ -2202,7 +2202,7 @@ impl Module {
|
|||||||
environ: ref mut e, ..
|
environ: ref mut e, ..
|
||||||
} = f.func
|
} = f.func
|
||||||
{
|
{
|
||||||
*e = Some(environ.clone())
|
*e = Some(environ.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -513,11 +513,13 @@ pub mod blob_functions {
|
|||||||
///
|
///
|
||||||
/// print(b); // prints "[030405]"
|
/// print(b); // prints "[030405]"
|
||||||
/// ```
|
/// ```
|
||||||
#[allow(clippy::cast_sign_loss, clippy::needless_pass_by_value)]
|
#[allow(clippy::cast_sign_loss, clippy::needless_pass_by_value, clippy::cast_possible_truncation)]
|
||||||
pub fn chop(blob: &mut Blob, len: INT) {
|
pub fn chop(blob: &mut Blob, len: INT) {
|
||||||
if !blob.is_empty() {
|
if !blob.is_empty() {
|
||||||
if len <= 0 {
|
if len <= 0 {
|
||||||
blob.clear();
|
blob.clear();
|
||||||
|
} else if len > MAX_USIZE_INT {
|
||||||
|
// len > BLOB length
|
||||||
} else if (len as usize) < blob.len() {
|
} else if (len as usize) < blob.len() {
|
||||||
blob.drain(0..blob.len() - len as usize);
|
blob.drain(0..blob.len() - len as usize);
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,10 @@ mod core_functions {
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
pub fn sleep(seconds: INT) {
|
pub fn sleep(seconds: INT) {
|
||||||
if seconds <= 0 {
|
if seconds > 0 {
|
||||||
return;
|
#[allow(clippy::cast_sign_loss)]
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(seconds as u64));
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_secs(seconds as u64));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a JSON string into a value.
|
/// Parse a JSON string into a value.
|
||||||
@ -142,23 +142,23 @@ mod reflection_functions {
|
|||||||
|
|
||||||
/// Return an array of object maps containing metadata of all script-defined functions.
|
/// Return an array of object maps containing metadata of all script-defined functions.
|
||||||
pub fn get_fn_metadata_list(ctx: NativeCallContext) -> Array {
|
pub fn get_fn_metadata_list(ctx: NativeCallContext) -> Array {
|
||||||
collect_fn_metadata(ctx, |_, _, _, _, _| true)
|
collect_fn_metadata(&ctx, |_, _, _, _, _| true)
|
||||||
}
|
}
|
||||||
/// Return an array of object maps containing metadata of all script-defined functions
|
/// Return an array of object maps containing metadata of all script-defined functions
|
||||||
/// matching the specified name.
|
/// matching the specified name.
|
||||||
#[rhai_fn(name = "get_fn_metadata_list")]
|
#[rhai_fn(name = "get_fn_metadata_list")]
|
||||||
pub fn get_fn_metadata(ctx: NativeCallContext, name: &str) -> Array {
|
pub fn get_fn_metadata(ctx: NativeCallContext, name: &str) -> Array {
|
||||||
collect_fn_metadata(ctx, |_, _, n, _, _| n == name)
|
collect_fn_metadata(&ctx, |_, _, n, _, _| n == name)
|
||||||
}
|
}
|
||||||
/// Return an array of object maps containing metadata of all script-defined functions
|
/// Return an array of object maps containing metadata of all script-defined functions
|
||||||
/// matching the specified name and arity (number of parameters).
|
/// matching the specified name and arity (number of parameters).
|
||||||
#[rhai_fn(name = "get_fn_metadata_list")]
|
#[rhai_fn(name = "get_fn_metadata_list")]
|
||||||
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||||
pub fn get_fn_metadata2(ctx: NativeCallContext, name: &str, params: INT) -> Array {
|
pub fn get_fn_metadata2(ctx: NativeCallContext, name: &str, params: INT) -> Array {
|
||||||
if !(0..=crate::MAX_USIZE_INT).contains(¶ms) {
|
if (0..=crate::MAX_USIZE_INT).contains(¶ms) {
|
||||||
Array::new()
|
collect_fn_metadata(&ctx, |_, _, n, p, _| p == (params as usize) && n == name)
|
||||||
} else {
|
} else {
|
||||||
collect_fn_metadata(ctx, |_, _, n, p, _| p == (params as usize) && n == name)
|
Array::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ mod reflection_functions {
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
fn collect_fn_metadata(
|
fn collect_fn_metadata(
|
||||||
ctx: NativeCallContext,
|
ctx: &NativeCallContext,
|
||||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared<crate::ast::ScriptFnDef>) -> bool
|
filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared<crate::ast::ScriptFnDef>) -> bool
|
||||||
+ Copy,
|
+ Copy,
|
||||||
) -> crate::Array {
|
) -> crate::Array {
|
||||||
|
@ -3560,7 +3560,9 @@ impl Engine {
|
|||||||
// try { try_block } catch ( var ) { catch_block }
|
// try { try_block } catch ( var ) { catch_block }
|
||||||
let branch = self.parse_block(input, state, lib, settings)?.into();
|
let branch = self.parse_block(input, state, lib, settings)?.into();
|
||||||
|
|
||||||
let expr = if !catch_var.is_empty() {
|
let expr = if catch_var.is_empty() {
|
||||||
|
Expr::Unit(catch_var.pos)
|
||||||
|
} else {
|
||||||
// Remove the error variable from the stack
|
// Remove the error variable from the stack
|
||||||
state.stack.as_deref_mut().unwrap().pop();
|
state.stack.as_deref_mut().unwrap().pop();
|
||||||
|
|
||||||
@ -3569,12 +3571,10 @@ impl Engine {
|
|||||||
None,
|
None,
|
||||||
catch_var.pos,
|
catch_var.pos,
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
Expr::Unit(catch_var.pos)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Stmt::TryCatch(
|
Ok(Stmt::TryCatch(
|
||||||
FlowControl { body, expr, branch }.into(),
|
FlowControl { expr, body, branch }.into(),
|
||||||
settings.pos,
|
settings.pos,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -1830,10 +1830,10 @@ fn get_next_token_inner(
|
|||||||
return Some((Token::NotIn, start_pos));
|
return Some((Token::NotIn, start_pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
stream.unget('i');
|
|
||||||
return Some((Token::Bang, start_pos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream.unget('i');
|
||||||
|
return Some((Token::Bang, start_pos));
|
||||||
}
|
}
|
||||||
('!', '=') => {
|
('!', '=') => {
|
||||||
eat_next_and_advance(stream, pos);
|
eat_next_and_advance(stream, pos);
|
||||||
@ -2137,7 +2137,7 @@ impl InputStream for MultiInputsStream<'_> {
|
|||||||
}
|
}
|
||||||
fn peek_next(&mut self) -> Option<char> {
|
fn peek_next(&mut self) -> Option<char> {
|
||||||
if let ch @ Some(..) = self.buf.last() {
|
if let ch @ Some(..) = self.buf.last() {
|
||||||
return ch.cloned();
|
return ch.copied();
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Loading…
Reference in New Issue
Block a user