From 7686ca619a376df315c31596dbdd9e5dc0f5bbd7 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 8 Feb 2022 09:46:14 +0800 Subject: [PATCH] Use .. for (_). --- codegen/src/function.rs | 18 ++++----- codegen/src/module.rs | 18 +++++---- codegen/src/rhai_module.rs | 6 +-- src/api/mod.rs | 2 +- src/ast/ast.rs | 6 +-- src/ast/expr.rs | 12 +++--- src/ast/stmt.rs | 22 +++++------ src/eval/chaining.rs | 4 +- src/eval/debugger.rs | 8 ++-- src/eval/expr.rs | 2 +- src/eval/stmt.rs | 4 +- src/eval/target.rs | 10 ++--- src/func/call.rs | 2 +- src/func/callable_function.rs | 70 +++++++++++++++++------------------ src/optimizer.rs | 10 ++--- src/parser.rs | 42 +++++++++++---------- src/tokenizer.rs | 12 +++--- src/types/error.rs | 36 +++++++++--------- tests/closures.rs | 2 +- tests/fn_ptr.rs | 2 +- tests/internal_fn.rs | 2 +- tests/modules.rs | 2 +- tests/operations.rs | 10 ++--- tests/stack.rs | 2 +- 24 files changed, 155 insertions(+), 149 deletions(-) diff --git a/codegen/src/function.rs b/codegen/src/function.rs index f0b14fd3..6cebaa03 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -366,7 +366,7 @@ impl Parse for ExportedFn { }) => { matches!(flatten_type_groups(elem.as_ref()), syn::Type::Path(ref p) if p.path == str_type_path) } - syn::Type::Verbatim(_) => false, + syn::Type::Verbatim(..) => false, _ => true, }; if !is_ok { @@ -381,13 +381,13 @@ impl Parse for ExportedFn { match fn_all.sig.output { syn::ReturnType::Type(.., ref ret_type) => { match flatten_type_groups(ret_type.as_ref()) { - syn::Type::Ptr(_) => { + syn::Type::Ptr(..) => { return Err(syn::Error::new( fn_all.sig.output.span(), "Rhai functions cannot return pointers", )) } - syn::Type::Reference(_) => { + syn::Type::Reference(..) => { return Err(syn::Error::new( fn_all.sig.output.span(), "Rhai functions cannot return references", @@ -544,28 +544,28 @@ impl ExportedFn { match params.special { // 2a. Property getters must take only the subject as an argument. - FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => { + FnSpecialAccess::Property(Property::Get(..)) if self.arg_count() != 1 => { return Err(syn::Error::new( self.signature.inputs.span(), "property getter requires exactly 1 parameter", )) } // 2b. Property getters must return a value. - FnSpecialAccess::Property(Property::Get(_)) if self.return_type().is_none() => { + FnSpecialAccess::Property(Property::Get(..)) if self.return_type().is_none() => { return Err(syn::Error::new( self.signature.span(), "property getter must return a value", )) } // 3a. Property setters must take the subject and a new value as arguments. - FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => { + FnSpecialAccess::Property(Property::Set(..)) if self.arg_count() != 2 => { return Err(syn::Error::new( self.signature.inputs.span(), "property setter requires exactly 2 parameters", )) } // 3b. Non-raw property setters must return nothing. - FnSpecialAccess::Property(Property::Set(_)) + FnSpecialAccess::Property(Property::Set(..)) if params.return_raw.is_none() && self.return_type().is_some() => { return Err(syn::Error::new( @@ -734,7 +734,7 @@ impl ExportedFn { .unwrap(), ); } - syn::FnArg::Receiver(_) => todo!("true self parameters not implemented yet"), + syn::FnArg::Receiver(..) => todo!("true self parameters not implemented yet"), } unpack_exprs.push(syn::parse2::(quote! { #var }).unwrap()); } else { @@ -811,7 +811,7 @@ impl ExportedFn { ); } } - syn::FnArg::Receiver(_) => panic!("internal error: how did this happen!?"), + syn::FnArg::Receiver(..) => panic!("internal error: how did this happen!?"), } if !is_ref { unpack_exprs.push(syn::parse2::(quote! { #var }).unwrap()); diff --git a/codegen/src/module.rs b/codegen/src/module.rs index 6942b69c..eaa43070 100644 --- a/codegen/src/module.rs +++ b/codegen/src/module.rs @@ -144,12 +144,14 @@ impl Parse for Module { attrs, ty, .. - }) if matches!(vis, syn::Visibility::Public(_)) => consts.push(ExportedConst { - name: ident.to_string(), - typ: ty.clone(), - expr: expr.as_ref().clone(), - cfg_attrs: crate::attrs::collect_cfg_attr(&attrs), - }), + }) if matches!(vis, syn::Visibility::Public(..)) => { + consts.push(ExportedConst { + name: ident.to_string(), + typ: ty.clone(), + expr: expr.as_ref().clone(), + cfg_attrs: crate::attrs::collect_cfg_attr(&attrs), + }) + } _ => {} } } @@ -161,7 +163,7 @@ impl Parse for Module { let mut i = 0; while i < content.len() { match content[i] { - syn::Item::Mod(_) => { + syn::Item::Mod(..) => { let mut item_mod = match content.remove(i) { syn::Item::Mod(m) => m, _ => unreachable!(), @@ -212,7 +214,7 @@ impl Module { pub fn update_scope(&mut self, parent_scope: &ExportScope) { let keep = match (self.params.skip, parent_scope) { (true, ..) => false, - (.., ExportScope::PubOnly) => matches!(self.mod_all.vis, syn::Visibility::Public(_)), + (.., ExportScope::PubOnly) => matches!(self.mod_all.vis, syn::Visibility::Public(..)), (.., ExportScope::Prefix(s)) => self.mod_all.ident.to_string().starts_with(s), (.., ExportScope::All) => true, }; diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index eda915f2..e3fd07af 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -99,7 +99,7 @@ pub fn generate_body( let fn_input_types: Vec<_> = function .arg_list() .map(|fn_arg| match fn_arg { - syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"), + syn::FnArg::Receiver(..) => panic!("internal error: receiver fn outside impl!?"), syn::FnArg::Typed(syn::PatType { ref ty, .. }) => { let arg_type = match flatten_type_groups(ty.as_ref()) { syn::Type::Reference(syn::TypeReference { @@ -150,7 +150,7 @@ pub fn generate_body( match function.params().special { FnSpecialAccess::None => (), - FnSpecialAccess::Index(_) | FnSpecialAccess::Property(_) => { + FnSpecialAccess::Index(..) | FnSpecialAccess::Property(..) => { let reg_name = fn_literal.value(); if reg_name.starts_with(FN_GET) || reg_name.starts_with(FN_SET) @@ -254,7 +254,7 @@ pub fn check_rename_collisions(fns: &[ExportedFn]) -> Result<(), syn::Error> { .arg_list() .fold(name.to_string(), |mut arg_str, fn_arg| { let type_string: String = match fn_arg { - syn::FnArg::Receiver(_) => unimplemented!("receiver rhai_fns not implemented"), + syn::FnArg::Receiver(..) => unimplemented!("receiver rhai_fns not implemented"), syn::FnArg::Typed(syn::PatType { ref ty, .. }) => print_type(ty), }; arg_str.push('.'); diff --git a/src/api/mod.rs b/src/api/mod.rs index b7d9b8f2..417ff39d 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -226,7 +226,7 @@ impl Engine { match Token::lookup_from_syntax(keyword.as_ref()) { // Standard identifiers, reserved keywords and custom keywords are OK - None | Some(Token::Reserved(_)) | Some(Token::Custom(_)) => (), + None | Some(Token::Reserved(..)) | Some(Token::Custom(..)) => (), // Active standard keywords cannot be made custom // Disabled keywords are OK Some(token) if token.is_standard_keyword() => { diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 02ea8545..0ccad835 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -449,7 +449,7 @@ impl AST { /// foo("!") /// "#)?; /// - /// // Merge 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1' + /// // Merge 'ast2', picking only 'error()' but not 'foo(..)', into 'ast1' /// let ast = ast1.merge_filtered(&ast2, |_, _, script, name, params| /// script && name == "error" && params == 0); /// @@ -551,7 +551,7 @@ impl AST { /// foo("!") /// "#)?; /// - /// // Combine 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1' + /// // Combine 'ast2', picking only 'error()' but not 'foo(..)', into 'ast1' /// ast1.combine_filtered(ast2, |_, _, script, name, params| /// script && name == "error" && params == 0); /// @@ -613,7 +613,7 @@ impl AST { /// fn bar() { print("hello"); } /// "#)?; /// - /// // Remove all functions except 'foo(_)' + /// // Remove all functions except 'foo(..)' /// ast.retain_functions(|_, _, name, params| name == "foo" && params == 1); /// # } /// # Ok(()) diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 75d23e9a..94e5b482 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -450,7 +450,7 @@ impl fmt::Debug for Expr { Self::FloatConstant(value, ..) => write!(f, "{:?}", value), Self::CharConstant(value, ..) => write!(f, "{:?}", value), Self::StringConstant(value, ..) => write!(f, "{:?}", value), - Self::Unit(_) => f.write_str("()"), + Self::Unit(..) => f.write_str("()"), Self::InterpolatedString(x, ..) => { f.write_str("InterpolatedString")?; @@ -535,7 +535,7 @@ impl Expr { Self::CharConstant(x, ..) => (*x).into(), Self::StringConstant(x, ..) => x.clone().into(), Self::BoolConstant(x, ..) => (*x).into(), - Self::Unit(_) => Dynamic::UNIT, + Self::Unit(..) => Dynamic::UNIT, #[cfg(not(feature = "no_index"))] Self::Array(x, ..) if self.is_constant() => { @@ -772,7 +772,7 @@ impl Expr { #[inline(always)] #[must_use] pub const fn is_unit(&self) -> bool { - matches!(self, Self::Unit(_)) + matches!(self, Self::Unit(..)) } /// Is the expression a constant? #[inline] @@ -787,7 +787,7 @@ impl Expr { | Self::IntegerConstant(..) | Self::CharConstant(..) | Self::StringConstant(..) - | Self::Unit(_) + | Self::Unit(..) | Self::Stack(..) => true, Self::InterpolatedString(x, ..) | Self::Array(x, ..) => x.iter().all(Self::is_constant), @@ -816,13 +816,13 @@ impl Expr { | Self::CharConstant(..) | Self::And(..) | Self::Or(..) - | Self::Unit(_) => false, + | Self::Unit(..) => false, Self::IntegerConstant(..) | Self::StringConstant(..) | Self::InterpolatedString(..) | Self::FnCall(..) - | Self::Stmt(_) + | Self::Stmt(..) | Self::Dot(..) | Self::Index(..) | Self::Array(..) diff --git a/src/ast/stmt.rs b/src/ast/stmt.rs index c33f5913..81f47d3d 100644 --- a/src/ast/stmt.rs +++ b/src/ast/stmt.rs @@ -404,7 +404,7 @@ impl Stmt { #[inline(always)] #[must_use] pub const fn is_noop(&self) -> bool { - matches!(self, Self::Noop(_)) + matches!(self, Self::Noop(..)) } /// Get the [position][Position] of this statement. #[must_use] @@ -432,7 +432,7 @@ impl Stmt { Self::Export(.., pos) => *pos, #[cfg(not(feature = "no_closure"))] - Self::Share(_) => Position::NONE, + Self::Share(..) => Position::NONE, } } /// Override the [position][Position] of this statement. @@ -462,7 +462,7 @@ impl Stmt { Self::Export(.., pos) => *pos = new_pos, #[cfg(not(feature = "no_closure"))] - Self::Share(_) => (), + Self::Share(..) => (), } self @@ -474,10 +474,10 @@ impl Stmt { Self::If(..) | Self::Switch(..) | Self::Block(..) - | Self::Expr(_) + | Self::Expr(..) | Self::FnCall(..) => true, - Self::Noop(_) | Self::While(..) | Self::Do(..) | Self::For(..) | Self::TryCatch(..) => { + Self::Noop(..) | Self::While(..) | Self::Do(..) | Self::For(..) | Self::TryCatch(..) => { false } @@ -487,7 +487,7 @@ impl Stmt { Self::Import(..) | Self::Export(..) => false, #[cfg(not(feature = "no_closure"))] - Self::Share(_) => false, + Self::Share(..) => false, } } /// Is this statement self-terminated (i.e. no need for a semicolon terminator)? @@ -502,13 +502,13 @@ impl Stmt { | Self::TryCatch(..) => true, // A No-op requires a semicolon in order to know it is an empty statement! - Self::Noop(_) => false, + Self::Noop(..) => false, Self::Expr(Expr::Custom(x, ..)) if x.is_self_terminated() => true, Self::Var(..) | Self::Assignment(..) - | Self::Expr(_) + | Self::Expr(..) | Self::FnCall(..) | Self::Do(..) | Self::BreakLoop(..) @@ -518,7 +518,7 @@ impl Stmt { Self::Import(..) | Self::Export(..) => false, #[cfg(not(feature = "no_closure"))] - Self::Share(_) => false, + Self::Share(..) => false, } } /// Is this statement _pure_? @@ -527,7 +527,7 @@ impl Stmt { #[must_use] pub fn is_pure(&self) -> bool { match self { - Self::Noop(_) => true, + Self::Noop(..) => true, Self::Expr(expr) => expr.is_pure(), Self::If(condition, x, ..) => { condition.is_pure() @@ -575,7 +575,7 @@ impl Stmt { Self::Export(..) => false, #[cfg(not(feature = "no_closure"))] - Self::Share(_) => false, + Self::Share(..) => false, } } /// Does this statement's behavior depend on its containing block? diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index 84c4a219..1185b720 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -724,7 +724,9 @@ impl Engine { match expr { #[cfg(not(feature = "no_object"))] - Expr::FnCall(x, ..) if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => { + Expr::FnCall(x, ..) + if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => + { let crate::ast::FnCallExpr { args, constants, .. } = x.as_ref(); diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 70aa50c2..d6f10ca0 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -465,16 +465,16 @@ impl Engine { // Skip transitive nodes match node { - ASTNode::Expr(Expr::Stmt(_)) | ASTNode::Stmt(Stmt::Expr(_)) => return Ok(None), + ASTNode::Expr(Expr::Stmt(..)) | ASTNode::Stmt(Stmt::Expr(..)) => return Ok(None), _ => (), } let stop = match global.debugger.status { DebuggerStatus::Next(false, false) => false, - DebuggerStatus::Next(true, false) => matches!(node, ASTNode::Stmt(_)), - DebuggerStatus::Next(false, true) => matches!(node, ASTNode::Expr(_)), + DebuggerStatus::Next(true, false) => matches!(node, ASTNode::Stmt(..)), + DebuggerStatus::Next(false, true) => matches!(node, ASTNode::Expr(..)), DebuggerStatus::Next(true, true) => true, - DebuggerStatus::FunctionExit(_) => false, + DebuggerStatus::FunctionExit(..) => false, }; let event = if stop { diff --git a/src/eval/expr.rs b/src/eval/expr.rs index a82504b1..f0e32227 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -324,7 +324,7 @@ impl Engine { Expr::StringConstant(x, ..) => Ok(x.clone().into()), Expr::CharConstant(x, ..) => Ok((*x).into()), Expr::BoolConstant(x, ..) => Ok((*x).into()), - Expr::Unit(_) => Ok(Dynamic::UNIT), + Expr::Unit(..) => Ok(Dynamic::UNIT), // `... ${...} ...` Expr::InterpolatedString(x, pos) => { diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index e57a9929..d81fc5e0 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -323,7 +323,7 @@ impl Engine { let result = match stmt { // No-op - Stmt::Noop(_) => Ok(Dynamic::UNIT), + Stmt::Noop(..) => Ok(Dynamic::UNIT), // Expression as statement Stmt::Expr(expr) => self @@ -483,7 +483,7 @@ impl Engine { } // Loop - Stmt::While(Expr::Unit(_), body, ..) => loop { + Stmt::While(Expr::Unit(..), body, ..) => loop { if !body.is_empty() { match self .eval_stmt_block(scope, global, state, lib, this_ptr, body, true, level) diff --git a/src/eval/target.rs b/src/eval/target.rs index f31647f9..eb046be2 100644 --- a/src/eval/target.rs +++ b/src/eval/target.rs @@ -144,10 +144,10 @@ impl<'a> Target<'a> { #[must_use] pub const fn is_ref(&self) -> bool { match self { - Self::RefMut(_) => true, + Self::RefMut(..) => true, #[cfg(not(feature = "no_closure"))] Self::SharedValue { .. } => true, - Self::TempValue(_) => false, + Self::TempValue(..) => false, #[cfg(not(feature = "no_index"))] Self::Bit { .. } | Self::BitField { .. } @@ -160,10 +160,10 @@ impl<'a> Target<'a> { #[must_use] pub const fn is_temp_value(&self) -> bool { match self { - Self::RefMut(_) => false, + Self::RefMut(..) => false, #[cfg(not(feature = "no_closure"))] Self::SharedValue { .. } => false, - Self::TempValue(_) => true, + Self::TempValue(..) => true, #[cfg(not(feature = "no_index"))] Self::Bit { .. } | Self::BitField { .. } @@ -275,7 +275,7 @@ impl<'a> Target<'a> { #[inline] pub fn propagate_changed_value(&mut self) -> RhaiResultOf<()> { match self { - Self::RefMut(_) | Self::TempValue(_) => (), + Self::RefMut(..) | Self::TempValue(..) => (), #[cfg(not(feature = "no_closure"))] Self::SharedValue { .. } => (), #[cfg(not(feature = "no_index"))] diff --git a/src/func/call.rs b/src/func/call.rs index bb19eda7..f4c6a07f 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -972,7 +972,7 @@ impl Engine { // Do not match function exit for arguments #[cfg(feature = "debugging")] let reset_debugger = global.debugger.clear_status_if(|status| { - matches!(status, crate::eval::DebuggerStatus::FunctionExit(_)) + matches!(status, crate::eval::DebuggerStatus::FunctionExit(..)) }); let result = self.eval_expr(scope, global, state, lib, this_ptr, arg_expr, level); diff --git a/src/func/callable_function.rs b/src/func/callable_function.rs index 3febb448..86e4d4f3 100644 --- a/src/func/callable_function.rs +++ b/src/func/callable_function.rs @@ -30,10 +30,10 @@ pub enum CallableFunction { impl fmt::Debug for CallableFunction { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Pure(_) => write!(f, "NativePureFunction"), - Self::Method(_) => write!(f, "NativeMethod"), - Self::Iterator(_) => write!(f, "NativeIterator"), - Self::Plugin(_) => write!(f, "PluginFunction"), + Self::Pure(..) => write!(f, "NativePureFunction"), + Self::Method(..) => write!(f, "NativeMethod"), + Self::Iterator(..) => write!(f, "NativeIterator"), + Self::Plugin(..) => write!(f, "PluginFunction"), #[cfg(not(feature = "no_function"))] Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f), @@ -44,10 +44,10 @@ impl fmt::Debug for CallableFunction { impl fmt::Display for CallableFunction { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Pure(_) => write!(f, "NativePureFunction"), - Self::Method(_) => write!(f, "NativeMethod"), - Self::Iterator(_) => write!(f, "NativeIterator"), - Self::Plugin(_) => write!(f, "PluginFunction"), + Self::Pure(..) => write!(f, "NativePureFunction"), + Self::Method(..) => write!(f, "NativeMethod"), + Self::Iterator(..) => write!(f, "NativeIterator"), + Self::Plugin(..) => write!(f, "PluginFunction"), #[cfg(not(feature = "no_function"))] Self::Script(s) => fmt::Display::fmt(s, f), @@ -61,13 +61,13 @@ impl CallableFunction { #[must_use] pub fn is_pure(&self) -> bool { match self { - Self::Pure(_) => true, - Self::Method(_) | Self::Iterator(_) => false, + Self::Pure(..) => true, + Self::Method(..) | Self::Iterator(..) => false, Self::Plugin(p) => !p.is_method_call(), #[cfg(not(feature = "no_function"))] - Self::Script(_) => false, + Self::Script(..) => false, } } /// Is this a native Rust method function? @@ -75,13 +75,13 @@ impl CallableFunction { #[must_use] pub fn is_method(&self) -> bool { match self { - Self::Method(_) => true, - Self::Pure(_) | Self::Iterator(_) => false, + Self::Method(..) => true, + Self::Pure(..) | Self::Iterator(..) => false, Self::Plugin(p) => p.is_method_call(), #[cfg(not(feature = "no_function"))] - Self::Script(_) => false, + Self::Script(..) => false, } } /// Is this an iterator function? @@ -89,11 +89,11 @@ impl CallableFunction { #[must_use] pub const fn is_iter(&self) -> bool { match self { - Self::Iterator(_) => true, - Self::Pure(_) | Self::Method(_) | Self::Plugin(_) => false, + Self::Iterator(..) => true, + Self::Pure(..) | Self::Method(..) | Self::Plugin(..) => false, #[cfg(not(feature = "no_function"))] - Self::Script(_) => false, + Self::Script(..) => false, } } /// Is this a script-defined function? @@ -105,8 +105,8 @@ impl CallableFunction { #[cfg(not(feature = "no_function"))] match self { - Self::Script(_) => true, - Self::Pure(_) | Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => false, + Self::Script(..) => true, + Self::Pure(..) | Self::Method(..) | Self::Iterator(..) | Self::Plugin(..) => false, } } /// Is this a plugin function? @@ -114,11 +114,11 @@ impl CallableFunction { #[must_use] pub const fn is_plugin_fn(&self) -> bool { match self { - Self::Plugin(_) => true, - Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => false, + Self::Plugin(..) => true, + Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => false, #[cfg(not(feature = "no_function"))] - Self::Script(_) => false, + Self::Script(..) => false, } } /// Is this a native Rust function? @@ -130,10 +130,10 @@ impl CallableFunction { #[cfg(not(feature = "no_function"))] match self { - Self::Pure(_) | Self::Method(_) => true, - Self::Plugin(_) => true, - Self::Iterator(_) => true, - Self::Script(_) => false, + Self::Pure(..) | Self::Method(..) => true, + Self::Plugin(..) => true, + Self::Iterator(..) => true, + Self::Script(..) => false, } } /// Get the access mode. @@ -145,8 +145,8 @@ impl CallableFunction { #[cfg(not(feature = "no_function"))] match self { - Self::Plugin(_) => FnAccess::Public, - Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => FnAccess::Public, + Self::Plugin(..) => FnAccess::Public, + Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => FnAccess::Public, Self::Script(f) => f.access, } } @@ -156,10 +156,10 @@ impl CallableFunction { pub fn get_native_fn(&self) -> Option<&Shared> { match self { Self::Pure(f) | Self::Method(f) => Some(f), - Self::Iterator(_) | Self::Plugin(_) => None, + Self::Iterator(..) | Self::Plugin(..) => None, #[cfg(not(feature = "no_function"))] - Self::Script(_) => None, + Self::Script(..) => None, } } /// Get a shared reference to a script-defined function definition. @@ -170,7 +170,7 @@ impl CallableFunction { #[must_use] pub const fn get_script_fn_def(&self) -> Option<&Shared> { match self { - Self::Pure(_) | Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => None, + Self::Pure(..) | Self::Method(..) | Self::Iterator(..) | Self::Plugin(..) => None, Self::Script(f) => Some(f), } } @@ -180,10 +180,10 @@ impl CallableFunction { pub fn get_iter_fn(&self) -> Option<&IteratorFn> { match self { Self::Iterator(f) => Some(f.as_ref()), - Self::Pure(_) | Self::Method(_) | Self::Plugin(_) => None, + Self::Pure(..) | Self::Method(..) | Self::Plugin(..) => None, #[cfg(not(feature = "no_function"))] - Self::Script(_) => None, + Self::Script(..) => None, } } /// Get a shared reference to a plugin function. @@ -192,10 +192,10 @@ impl CallableFunction { pub fn get_plugin_fn(&self) -> Option<&Shared> { match self { Self::Plugin(f) => Some(f), - Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => None, + Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => None, #[cfg(not(feature = "no_function"))] - Self::Script(_) => None, + Self::Script(..) => None, } } /// Create a new [`CallableFunction::Pure`]. diff --git a/src/optimizer.rs b/src/optimizer.rs index f53c51ac..e8ddf4f8 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -349,7 +349,7 @@ fn optimize_stmt_block( .map_or_else(|| Stmt::Noop(pos), |e| Stmt::Expr(mem::take(e))); } // { ...; stmt; noop } -> done - [.., ref second_last_stmt, Stmt::Noop(_)] + [.., ref second_last_stmt, Stmt::Noop(..)] if second_last_stmt.returns_value() => { break @@ -636,7 +636,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b if let Some(mut condition) = mem::take(&mut block.condition) { optimize_expr(&mut condition, state, false); match condition { - Expr::Unit(_) | Expr::BoolConstant(true, ..) => state.set_dirty(), + Expr::Unit(..) | Expr::BoolConstant(true, ..) => state.set_dirty(), _ => block.condition = Some(condition), } } @@ -665,7 +665,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b if let Some(mut condition) = mem::take(&mut block.condition) { optimize_expr(&mut condition, state, false); match condition { - Expr::Unit(_) | Expr::BoolConstant(true, ..) => state.set_dirty(), + Expr::Unit(..) | Expr::BoolConstant(true, ..) => state.set_dirty(), _ => block.condition = Some(condition), } } @@ -941,8 +941,8 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) { while n < x.len() - 1 { match (mem::take(&mut x[n]), mem::take(&mut x[n+1])) { (Expr::StringConstant(mut s1, pos), Expr::StringConstant(s2, ..)) => { s1 += s2; x[n] = Expr::StringConstant(s1, pos); x.remove(n+1); state.set_dirty(); } - (expr1, Expr::Unit(_)) => { x[n] = expr1; x.remove(n+1); state.set_dirty(); } - (Expr::Unit(_), expr2) => { x[n+1] = expr2; x.remove(n); state.set_dirty(); } + (expr1, Expr::Unit(..)) => { x[n] = expr1; x.remove(n+1); state.set_dirty(); } + (Expr::Unit(..), expr2) => { x[n+1] = expr2; x.remove(n); state.set_dirty(); } (expr1, Expr::StringConstant(s, ..)) if s.is_empty() => { x[n] = expr1; x.remove(n+1); state.set_dirty(); } (Expr::StringConstant(s, ..), expr2) if s.is_empty()=> { x[n+1] = expr2; x.remove(n); state.set_dirty(); } (expr1, expr2) => { x[n] = expr1; x[n+1] = expr2; n += 1; } diff --git a/src/parser.rs b/src/parser.rs index df637d7a..e9e382e4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -291,7 +291,7 @@ impl Expr { /// Raise an error if the expression can never yield a boolean value. fn ensure_bool_expr(self) -> ParseResult { let type_name = match self { - Expr::Unit(_) => "()", + Expr::Unit(..) => "()", Expr::DynamicConstant(ref v, ..) if !v.is::() => v.type_name(), Expr::IntegerConstant(..) => "a number", #[cfg(not(feature = "no_float"))] @@ -312,7 +312,7 @@ impl Expr { /// Raise an error if the expression can never yield an iterable value. fn ensure_iterable(self) -> ParseResult { let type_name = match self { - Expr::Unit(_) => "()", + Expr::Unit(..) => "()", Expr::BoolConstant(..) => "a boolean", Expr::IntegerConstant(..) => "a number", #[cfg(not(feature = "no_float"))] @@ -661,7 +661,7 @@ fn parse_index_chain( | Expr::And(..) | Expr::Or(..) | Expr::BoolConstant(..) - | Expr::Unit(_) => { + | Expr::Unit(..) => { return Err(PERR::MalformedIndexExpr( "Only arrays, object maps and strings can be indexed".into(), ) @@ -694,7 +694,7 @@ fn parse_index_chain( | Expr::And(..) | Expr::Or(..) | Expr::BoolConstant(..) - | Expr::Unit(_) => { + | Expr::Unit(..) => { return Err(PERR::MalformedIndexExpr( "Only arrays, object maps and strings can be indexed".into(), ) @@ -720,7 +720,7 @@ fn parse_index_chain( .into_err(x.start_position())) } // lhs[()] - x @ Expr::Unit(_) => { + x @ Expr::Unit(..) => { return Err(PERR::MalformedIndexExpr( "Array access expects integer index, not ()".into(), ) @@ -897,7 +897,9 @@ fn parse_map_literal( } (s, pos) } - (Token::InterpolatedString(_), pos) => return Err(PERR::PropertyExpected.into_err(pos)), + (Token::InterpolatedString(..), pos) => { + return Err(PERR::PropertyExpected.into_err(pos)) + } (Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => { return Err(PERR::Reserved(s.to_string()).into_err(pos)); } @@ -951,7 +953,7 @@ fn parse_map_literal( eat_token(input, Token::Comma); } (Token::RightBrace, ..) => (), - (Token::Identifier(_), pos) => { + (Token::Identifier(..), pos) => { return Err(PERR::MissingToken( Token::Comma.into(), "to separate the items of this object map literal".into(), @@ -1147,7 +1149,7 @@ fn parse_switch( ) .into_err(*pos)) } - (..) => (), + _ => (), } } @@ -1183,9 +1185,9 @@ fn parse_primary( let root_expr = match token { Token::EOF => return Err(PERR::UnexpectedEOF.into_err(settings.pos)), - Token::IntegerConstant(_) - | Token::CharConstant(_) - | Token::StringConstant(_) + Token::IntegerConstant(..) + | Token::CharConstant(..) + | Token::StringConstant(..) | Token::True | Token::False => match input.next().expect(NEVER_ENDS).0 { Token::IntegerConstant(x) => Expr::IntegerConstant(x, settings.pos), @@ -1284,7 +1286,7 @@ fn parse_primary( } // Interpolated string - Token::InterpolatedString(_) => { + Token::InterpolatedString(..) => { let mut segments = StaticVec::::new(); match input.next().expect(NEVER_ENDS) { @@ -1352,7 +1354,7 @@ fn parse_primary( } // Identifier - Token::Identifier(_) => { + Token::Identifier(..) => { #[cfg(not(feature = "no_module"))] let none = None; #[cfg(feature = "no_module")] @@ -1416,7 +1418,7 @@ fn parse_primary( } // Reserved keyword or symbol - Token::Reserved(_) => { + Token::Reserved(..) => { #[cfg(not(feature = "no_module"))] let none = None; #[cfg(feature = "no_module")] @@ -1450,7 +1452,7 @@ fn parse_primary( } } - Token::LexError(_) => match input.next().expect(NEVER_ENDS) { + Token::LexError(..) => match input.next().expect(NEVER_ENDS) { (Token::LexError(err), ..) => return Err(err.into_err(settings.pos)), token => unreachable!("Token::LexError expected but gets {:?}", token), }, @@ -1575,7 +1577,7 @@ fn parse_postfix( (expr, Token::Period) => { // Expression after dot must start with an identifier match input.peek().expect(NEVER_ENDS) { - (Token::Identifier(_), ..) => { + (Token::Identifier(..), ..) => { #[cfg(not(feature = "no_closure"))] { // Prevents capturing of the object properties as vars: xxx. @@ -2792,7 +2794,7 @@ fn parse_block( eat_token(input, Token::SemiColon); } // { ... { stmt } ??? - (..) if !need_semicolon => (), + _ if !need_semicolon => (), // { ... stmt (Token::LexError(err), err_pos) => return Err(err.clone().into_err(*err_pos)), // { ... stmt ??? @@ -2874,7 +2876,7 @@ fn parse_stmt( match input.peek().expect(NEVER_ENDS) { (Token::Fn, ..) | (Token::Private, ..) => break, - (Token::Comment(_), ..) => (), + (Token::Comment(..), ..) => (), _ => return Err(PERR::WrongDocComment.into_err(comments_pos)), } } @@ -3027,7 +3029,7 @@ fn parse_stmt( // `return;` or `throw;` (Token::SemiColon, ..) => Ok(Stmt::Return(return_type, None, token_pos)), // `return` or `throw` with expression - (..) => { + _ => { let expr = parse_expr(input, state, lib, settings.level_up())?; Ok(Stmt::Return(return_type, Some(expr), token_pos)) } @@ -3491,7 +3493,7 @@ impl Engine { // stmt ; (Token::SemiColon, ..) if !need_semicolon => (), // { stmt } ??? - (..) if !need_semicolon => (), + _ if !need_semicolon => (), // stmt (Token::LexError(err), pos) => return Err(err.clone().into_err(*pos)), // stmt ??? diff --git a/src/tokenizer.rs b/src/tokenizer.rs index e1b2081b..ecc887aa 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -603,8 +603,8 @@ impl Token { FloatConstant(f) => f.to_string().into(), #[cfg(feature = "decimal")] DecimalConstant(d) => d.to_string().into(), - StringConstant(_) => "string".into(), - InterpolatedString(_) => "string".into(), + StringConstant(..) => "string".into(), + InterpolatedString(..) => "string".into(), CharConstant(c) => c.to_string().into(), Identifier(s) => s.to_string().into(), Reserved(s) => s.to_string().into(), @@ -825,7 +825,7 @@ impl Token { use Token::*; match self { - LexError(_) | + LexError(..) | SemiColon | // ; - is unary Colon | // #{ foo: - is unary Comma | // ( ... , -expr ) - is unary @@ -970,7 +970,7 @@ impl Token { #[inline(always)] #[must_use] pub const fn is_reserved(&self) -> bool { - matches!(self, Self::Reserved(_)) + matches!(self, Self::Reserved(..)) } /// Convert a token into a function name, if possible. @@ -987,7 +987,7 @@ impl Token { #[inline(always)] #[must_use] pub const fn is_custom(&self) -> bool { - matches!(self, Self::Custom(_)) + matches!(self, Self::Custom(..)) } } @@ -2197,7 +2197,7 @@ impl<'a> Iterator for TokenIterator<'a> { // a verbatim string or a string with continuation encounters {EOF}. // This is necessary to handle such cases for line-by-line parsing, but for an entire // script it is a syntax error. - Some((Token::StringConstant(_), pos)) if self.state.is_within_text_terminated_by.is_some() => { + Some((Token::StringConstant(..), pos)) if self.state.is_within_text_terminated_by.is_some() => { self.state.is_within_text_terminated_by = None; return Some((Token::LexError(LERR::UnterminatedString), pos)); } diff --git a/src/types/error.rs b/src/types/error.rs index 93044334..e79d7ec8 100644 --- a/src/types/error.rs +++ b/src/types/error.rs @@ -153,11 +153,11 @@ impl fmt::Display for EvalAltResult { s => f.write_str(s), }?, Self::ErrorIndexingType(s, ..) => write!(f, "Indexer not registered: {}", s)?, - Self::ErrorUnboundThis(_) => f.write_str("'this' is not bound")?, - Self::ErrorFor(_) => f.write_str("For loop expects a type that is iterable")?, - Self::ErrorTooManyOperations(_) => f.write_str("Too many operations")?, - Self::ErrorTooManyModules(_) => f.write_str("Too many modules imported")?, - Self::ErrorStackOverflow(_) => f.write_str("Stack overflow")?, + Self::ErrorUnboundThis(..) => f.write_str("'this' is not bound")?, + Self::ErrorFor(..) => f.write_str("For loop expects a type that is iterable")?, + Self::ErrorTooManyOperations(..) => f.write_str("Too many operations")?, + Self::ErrorTooManyModules(..) => f.write_str("Too many modules imported")?, + Self::ErrorStackOverflow(..) => f.write_str("Stack overflow")?, Self::ErrorTerminated(..) => f.write_str("Script terminated")?, Self::ErrorRuntime(d, ..) if d.is::<()>() => f.write_str("Runtime error")?, @@ -270,13 +270,13 @@ impl EvalAltResult { Self::ErrorFunctionNotFound(..) | Self::ErrorInFunctionCall(..) | Self::ErrorInModule(..) - | Self::ErrorUnboundThis(_) + | Self::ErrorUnboundThis(..) | Self::ErrorMismatchDataType(..) | Self::ErrorArrayBounds(..) | Self::ErrorStringBounds(..) | Self::ErrorBitFieldBounds(..) | Self::ErrorIndexingType(..) - | Self::ErrorFor(_) + | Self::ErrorFor(..) | Self::ErrorVariableExists(..) | Self::ErrorVariableNotFound(..) | Self::ErrorModuleNotFound(..) @@ -293,9 +293,9 @@ impl EvalAltResult { // Therefore, this error should not be catchable. Self::ErrorCustomSyntax(..) => false, - Self::ErrorTooManyOperations(_) - | Self::ErrorTooManyModules(_) - | Self::ErrorStackOverflow(_) + Self::ErrorTooManyOperations(..) + | Self::ErrorTooManyModules(..) + | Self::ErrorStackOverflow(..) | Self::ErrorDataTooLarge(..) | Self::ErrorTerminated(..) => false, @@ -310,9 +310,9 @@ impl EvalAltResult { Self::ErrorParsing(..) => true, Self::ErrorCustomSyntax(..) - | Self::ErrorTooManyOperations(_) - | Self::ErrorTooManyModules(_) - | Self::ErrorStackOverflow(_) + | Self::ErrorTooManyOperations(..) + | Self::ErrorTooManyModules(..) + | Self::ErrorStackOverflow(..) | Self::ErrorDataTooLarge(..) => true, Self::ErrorTerminated(..) => true, @@ -337,12 +337,12 @@ impl EvalAltResult { Self::ErrorSystem(..) | Self::ErrorParsing(..) - | Self::ErrorUnboundThis(_) - | Self::ErrorFor(_) + | Self::ErrorUnboundThis(..) + | Self::ErrorFor(..) | Self::ErrorArithmetic(..) - | Self::ErrorTooManyOperations(_) - | Self::ErrorTooManyModules(_) - | Self::ErrorStackOverflow(_) + | Self::ErrorTooManyOperations(..) + | Self::ErrorTooManyModules(..) + | Self::ErrorStackOverflow(..) | Self::ErrorRuntime(..) => (), Self::ErrorFunctionNotFound(f, ..) => { diff --git a/tests/closures.rs b/tests/closures.rs index 8a323f97..36ae9e33 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -48,7 +48,7 @@ fn test_closures() -> Result<(), Box> { .compile_expression("let f = |x| {};") .expect_err("should error") .0, - ParseErrorType::BadInput(_) + ParseErrorType::BadInput(..) )); assert_eq!( diff --git a/tests/fn_ptr.rs b/tests/fn_ptr.rs index 41ad29af..0944ea58 100644 --- a/tests/fn_ptr.rs +++ b/tests/fn_ptr.rs @@ -74,7 +74,7 @@ fn test_fn_ptr() -> Result<(), Box> { ) .expect_err("should error"), EvalAltResult::ErrorInFunctionCall(fn_name, _, err, ..) - if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(_)) + if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(..)) )); Ok(()) diff --git a/tests/internal_fn.rs b/tests/internal_fn.rs index 62bf001d..72808e96 100644 --- a/tests/internal_fn.rs +++ b/tests/internal_fn.rs @@ -249,7 +249,7 @@ fn test_internal_fn_bang() -> Result<(), Box> { ) .expect_err("should error") .0, - ParseErrorType::MalformedCapture(_) + ParseErrorType::MalformedCapture(..) )); Ok(()) diff --git a/tests/modules.rs b/tests/modules.rs index 63409844..25e17117 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -214,7 +214,7 @@ fn test_module_resolver() -> Result<(), Box> { "# ) .expect_err("should error"), - EvalAltResult::ErrorTooManyModules(_) + EvalAltResult::ErrorTooManyModules(..) )); #[cfg(not(feature = "no_function"))] diff --git a/tests/operations.rs b/tests/operations.rs index b5b73ebd..d6b7b69f 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -19,7 +19,7 @@ fn test_max_operations() -> Result<(), Box> { assert!(matches!( *engine.run("for x in 0..500 {}").expect_err("should error"), - EvalAltResult::ErrorTooManyOperations(_) + EvalAltResult::ErrorTooManyOperations(..) )); engine.set_max_operations(0); @@ -44,7 +44,7 @@ fn test_max_operations_literal() -> Result<(), Box> { *engine .run("[1, 2, 3, 4, 5, 6, 7, 8, 9]") .expect_err("should error"), - EvalAltResult::ErrorTooManyOperations(_) + EvalAltResult::ErrorTooManyOperations(..) )); #[cfg(not(feature = "no_object"))] @@ -55,7 +55,7 @@ fn test_max_operations_literal() -> Result<(), Box> { *engine .run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}") .expect_err("should error"), - EvalAltResult::ErrorTooManyOperations(_) + EvalAltResult::ErrorTooManyOperations(..) )); Ok(()) @@ -111,7 +111,7 @@ fn test_max_operations_functions() -> Result<(), Box> { "#, ) .expect_err("should error"), - EvalAltResult::ErrorTooManyOperations(_) + EvalAltResult::ErrorTooManyOperations(..) )); Ok(()) @@ -138,7 +138,7 @@ fn test_max_operations_eval() -> Result<(), Box> { "# ) .expect_err("should error"), - EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(_)) + EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(..)) )); Ok(()) diff --git a/tests/stack.rs b/tests/stack.rs index c2a8d21d..c10b4133 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -29,7 +29,7 @@ fn test_stack_overflow_fn_calls() -> Result<(), Box> { max + 1 )) .expect_err("should error"), - EvalAltResult::ErrorStackOverflow(_) + EvalAltResult::ErrorStackOverflow(..) )); Ok(())