Skip to content

Commit

Permalink
Merge pull request #758 from schungx/master
Browse files Browse the repository at this point in the history
Satisfy clippy.
  • Loading branch information
schungx committed Sep 7, 2023
2 parents 80df84a + 5128f90 commit fe939a8
Show file tree
Hide file tree
Showing 57 changed files with 1,029 additions and 865 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -31,6 +31,11 @@ Dependencies
* [`syn`](https://crates.io/crates/syn) in [`rhai_codegen`](https://crates.io/crates/rhai_codegen) is bumped to version 2.
* [`hashbrown`](https://crates.io/crates/hashbrown) (used in `no-std` builds) is bumped to version 0.14.

Deprecated API's
----------------

* `ParseErrorType::MalformedCallExpr` and `ParseErrorType::MalformedInExpr` are deprecated and will be removed in the next major version.

New features
------------

Expand Down
6 changes: 3 additions & 3 deletions codegen/src/function.rs
Expand Up @@ -105,7 +105,7 @@ pub const FN_IDX_SET: &str = "index$set$";
impl Parse for ExportedFnParams {
fn parse(args: ParseStream) -> syn::Result<Self> {
if args.is_empty() {
return Ok(ExportedFnParams::default());
return Ok(<_>::default());
}

let info = crate::attrs::parse_attr_items(args)?;
Expand All @@ -119,7 +119,7 @@ impl ExportedParams for ExportedFnParams {
}

fn no_attrs() -> Self {
Default::default()
Self::default()
}

fn from_info(info: crate::attrs::ExportInfo) -> syn::Result<Self> {
Expand Down Expand Up @@ -388,7 +388,7 @@ impl Parse for ExportedFn {
visibility,
pass_context,
mut_receiver,
params: Default::default(),
params: <_>::default(),
cfg_attrs,
#[cfg(feature = "metadata")]
comments: Vec::new(),
Expand Down
6 changes: 3 additions & 3 deletions codegen/src/module.rs
Expand Up @@ -22,7 +22,7 @@ pub struct ExportedModParams {
impl Parse for ExportedModParams {
fn parse(args: ParseStream) -> syn::Result<Self> {
if args.is_empty() {
return Ok(ExportedModParams::default());
return Ok(<_>::default());
}

Self::from_info(crate::attrs::parse_attr_items(args)?)
Expand All @@ -35,7 +35,7 @@ impl ExportedParams for ExportedModParams {
}

fn no_attrs() -> Self {
Default::default()
Self::default()
}

fn from_info(info: ExportInfo) -> syn::Result<Self> {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Parse for Module {
consts,
custom_types,
sub_modules,
params: ExportedModParams::default(),
params: <_>::default(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handler_map/main.rs
Expand Up @@ -62,7 +62,7 @@ pub fn main() {

// Prevent shadowing of `state`
#[allow(deprecated)]
engine.on_def_var(|_, info, _| Ok(info.name != "state"));
engine.on_def_var(|_, info, _| Ok(info.name() != "state"));

// Create a custom 'Scope' to hold state
let mut scope = Scope::new();
Expand Down
6 changes: 3 additions & 3 deletions src/api/call_fn.rs
Expand Up @@ -117,7 +117,7 @@ impl Engine {
name: impl AsRef<str>,
args: impl FuncArgs,
) -> RhaiResultOf<T> {
self.call_fn_with_options(CallFnOptions::default(), scope, ast, name, args)
self.call_fn_with_options(<_>::default(), scope, ast, name, args)
}
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments.
///
Expand Down Expand Up @@ -182,8 +182,8 @@ impl Engine {
result.try_cast_raw().map_err(|r| {
let result_type = self.map_type_name(r.type_name());
let cast_type = match type_name::<T>() {
typ @ _ if typ.contains("::") => self.map_type_name(typ),
typ @ _ => typ,
typ if typ.contains("::") => self.map_type_name(typ),
typ => typ,
};
ERR::ErrorMismatchOutputType(cast_type.into(), result_type.into(), Position::NONE)
.into()
Expand Down
30 changes: 12 additions & 18 deletions src/api/compile.rs
Expand Up @@ -227,15 +227,12 @@ impl Engine {

let mut interner;
let mut guard;
let interned_strings = match self.interned_strings {
Some(ref interner) => {
guard = locked_write(interner);
&mut *guard
}
None => {
interner = StringsInterner::new();
&mut interner
}
let interned_strings = if let Some(ref interner) = self.interned_strings {
guard = locked_write(interner);
&mut *guard
} else {
interner = StringsInterner::new();
&mut interner
};

let state = &mut ParseState::new(scope, interned_strings, tc);
Expand Down Expand Up @@ -311,15 +308,12 @@ impl Engine {

let mut interner;
let mut guard;
let interned_strings = match self.interned_strings {
Some(ref interner) => {
guard = locked_write(interner);
&mut *guard
}
None => {
interner = StringsInterner::new();
&mut interner
}
let interned_strings = if let Some(ref interner) = self.interned_strings {
guard = locked_write(interner);
&mut *guard
} else {
interner = StringsInterner::new();
&mut interner
};

let state = &mut ParseState::new(Some(scope), interned_strings, t);
Expand Down
4 changes: 2 additions & 2 deletions src/api/definitions/mod.rs
Expand Up @@ -34,7 +34,7 @@ impl Engine {
Definitions {
engine: self,
scope: None,
config: DefinitionsConfig::default(),
config: <_>::default(),
}
}

Expand All @@ -61,7 +61,7 @@ impl Engine {
Definitions {
engine: self,
scope: Some(scope),
config: DefinitionsConfig::default(),
config: <_>::default(),
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/api/deprecated.rs
Expand Up @@ -164,7 +164,7 @@ impl Engine {
this_ptr,
eval_ast,
rewind_scope,
..Default::default()
..<_>::default()
};

self._call_fn(
Expand Down Expand Up @@ -614,7 +614,7 @@ impl Module {
#[inline(always)]
#[must_use]
#[deprecated(since = "1.12.0", note = "use `new` instead")]
pub fn with_capacity(_capacity: usize) -> Self {
pub const fn with_capacity(_capacity: usize) -> Self {
Self::new()
}
}
Expand Down Expand Up @@ -904,7 +904,8 @@ pub mod deprecated_array_functions {
array: &mut Array,
comparer: &str,
) -> RhaiResultOf<()> {
Ok(dedup_by_comparer(ctx, array, FnPtr::new(comparer)?))
dedup_by_comparer(ctx, array, FnPtr::new(comparer)?);
Ok(())
}
/// Reduce an array by iterating through all elements while applying a function named by `reducer`.
///
Expand Down Expand Up @@ -1120,7 +1121,8 @@ pub mod deprecated_array_functions {
array: &mut Array,
comparer: &str,
) -> RhaiResultOf<()> {
Ok(sort(ctx, array, FnPtr::new(comparer)?))
sort(ctx, array, FnPtr::new(comparer)?);
Ok(())
}
/// Remove all elements in the array that returns `true` when applied a function named by `filter`
/// and return them as a new array.
Expand Down
21 changes: 9 additions & 12 deletions src/api/eval.rs
Expand Up @@ -122,15 +122,12 @@ impl Engine {
let ast = {
let mut interner;
let mut guard;
let interned_strings = match self.interned_strings {
Some(ref interner) => {
guard = locked_write(interner);
&mut *guard
}
None => {
interner = StringsInterner::new();
&mut interner
}
let interned_strings = if let Some(ref interner) = self.interned_strings {
guard = locked_write(interner);
&mut *guard
} else {
interner = StringsInterner::new();
&mut interner
};

let (stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref());
Expand All @@ -145,7 +142,7 @@ impl Engine {
#[cfg(not(feature = "no_optimize"))]
OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
OptimizationLevel::default(),
<_>::default(),
)?
};

Expand Down Expand Up @@ -217,8 +214,8 @@ impl Engine {

result.try_cast_raw::<T>().map_err(|v| {
let typename = match type_name::<T>() {
typ @ _ if typ.contains("::") => self.map_type_name(typ),
typ @ _ => typ,
typ if typ.contains("::") => self.map_type_name(typ),
typ => typ,
};

ERR::ErrorMismatchOutputType(
Expand Down
38 changes: 32 additions & 6 deletions src/api/events.rs
Expand Up @@ -7,16 +7,42 @@ use std::prelude::v1::*;

/// Information on a variable definition.
#[derive(Debug, Hash)]
#[non_exhaustive]
pub struct VarDefInfo<'a> {
/// Name of the variable to be defined.
pub name: &'a str,
pub(crate) name: &'a str,
/// `true` if the statement is `const`, otherwise it is `let`.
pub is_const: bool,
pub(crate) is_const: bool,
/// The current nesting level, with zero being the global level.
pub nesting_level: usize,
pub(crate) nesting_level: usize,
/// Will the variable _shadow_ an existing variable?
pub will_shadow: bool,
pub(crate) will_shadow: bool,
}

impl<'a> VarDefInfo<'a> {
/// Name of the variable to be defined.
#[inline(always)]
#[must_use]
pub const fn name(&self) -> &str {
self.name
}
/// `true` if the statement is `const`, otherwise it is `let`.
#[inline(always)]
#[must_use]
pub const fn is_const(&self) -> bool {
self.is_const
}
/// The current nesting level, with zero being the global level.
#[inline(always)]
#[must_use]
pub const fn nesting_level(&self) -> usize {
self.nesting_level
}
/// Will the variable _shadow_ an existing variable?
#[inline(always)]
#[must_use]
pub const fn will_shadow_other_variables(&self) -> bool {
self.will_shadow
}
}

impl Engine {
Expand Down Expand Up @@ -115,7 +141,7 @@ impl Engine {
/// // Register a variable definition filter.
/// engine.on_def_var(|_, info, _| {
/// // Disallow defining MYSTIC_NUMBER as a constant
/// if info.name == "MYSTIC_NUMBER" && info.is_const {
/// if info.name() == "MYSTIC_NUMBER" && info.is_const() {
/// Ok(false)
/// } else {
/// Ok(true)
Expand Down
2 changes: 2 additions & 0 deletions src/api/formatting.rs
Expand Up @@ -210,6 +210,7 @@ impl Engine {
.global_sub_modules
.values()
.find_map(|m| m.get_custom_type(name));

#[cfg(feature = "no_module")]
return None;
})
Expand Down Expand Up @@ -240,6 +241,7 @@ impl Engine {
.global_sub_modules
.values()
.find_map(|m| m.get_custom_type(name));

#[cfg(feature = "no_module")]
return None;
})
Expand Down
17 changes: 7 additions & 10 deletions src/api/json.rs
Expand Up @@ -118,15 +118,12 @@ impl Engine {
let ast = {
let mut interner;
let mut guard;
let interned_strings = match self.interned_strings {
Some(ref interner) => {
guard = locked_write(interner);
&mut *guard
}
None => {
interner = StringsInterner::new();
&mut interner
}
let interned_strings = if let Some(ref interner) = self.interned_strings {
guard = locked_write(interner);
&mut *guard
} else {
interner = StringsInterner::new();
&mut interner
};

let state = &mut ParseState::new(None, interned_strings, tokenizer_control);
Expand All @@ -138,7 +135,7 @@ impl Engine {
#[cfg(not(feature = "no_optimize"))]
OptimizationLevel::None,
#[cfg(feature = "no_optimize")]
OptimizationLevel::default(),
<_>::default(),
)?
};

Expand Down
1 change: 1 addition & 0 deletions src/api/mod.rs
Expand Up @@ -128,6 +128,7 @@ impl Engine {
/// assert!(engine.is_symbol_disabled("if"));
/// ```
#[inline(always)]
#[must_use]
pub fn is_symbol_disabled(&self, symbol: &str) -> bool {
self.disabled_symbols.contains(symbol)
}
Expand Down

0 comments on commit fe939a8

Please sign in to comment.