Satisfy clippy.

This commit is contained in:
Stephen Chung 2022-11-25 09:46:13 +08:00
parent 2bf8e610a3
commit 6600862c22
13 changed files with 107 additions and 123 deletions

View File

@ -12,7 +12,7 @@ use crate::{
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{borrow::Borrow, collections::BTreeMap, ops::Deref};
use std::{borrow::Borrow, ops::Deref};
/// Collection of special markers for custom syntax definition.
pub mod markers {
@ -268,7 +268,7 @@ impl Engine {
.map_or(false, |m| m.contains_key(s))
{
self.custom_keywords
.get_or_insert_with(|| BTreeMap::new().into())
.get_or_insert_with(Default::default)
.insert(s.into(), None);
}
s.into()
@ -304,7 +304,7 @@ impl Engine {
.map_or(false, |m| m.contains_key(s)))
{
self.custom_keywords
.get_or_insert_with(|| BTreeMap::new().into())
.get_or_insert_with(Default::default)
.insert(s.into(), None);
}
s.into()
@ -391,7 +391,7 @@ impl Engine {
func: impl Fn(&mut EvalContext, &[Expression], &Dynamic) -> RhaiResult + SendSync + 'static,
) -> &mut Self {
self.custom_syntax
.get_or_insert_with(|| BTreeMap::new().into())
.get_or_insert_with(Default::default)
.insert(
key.into(),
CustomSyntax {

View File

@ -35,7 +35,6 @@ pub mod definitions;
use crate::{Dynamic, Engine, Identifier};
use std::collections::BTreeSet;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -109,7 +108,7 @@ impl Engine {
#[inline(always)]
pub fn disable_symbol(&mut self, symbol: impl Into<Identifier>) -> &mut Self {
self.disabled_symbols
.get_or_insert_with(|| BTreeSet::new().into())
.get_or_insert_with(Default::default)
.insert(symbol.into());
self
}
@ -199,7 +198,7 @@ impl Engine {
// Add to custom keywords
self.custom_keywords
.get_or_insert_with(|| std::collections::BTreeMap::new().into())
.get_or_insert_with(Default::default)
.insert(keyword.into(), Some(precedence));
Ok(self)

View File

@ -720,8 +720,7 @@ impl Engine {
}
register_static_module_raw(
self.global_sub_modules
.get_or_insert_with(|| BTreeMap::new().into()),
self.global_sub_modules.get_or_insert_with(Default::default),
name.as_ref(),
module,
);

View File

@ -121,7 +121,7 @@ impl<T: 'static> SusLock<T> {
#[must_use]
pub fn get(&self) -> Option<&'static T> {
if self.initialized.load(Ordering::SeqCst) {
let hokma = hokmalock(unsafe { mem::transmute(self.data.get()) });
let hokma = hokmalock(self.data.get() as usize);
// we forgo the optimistic read, because we don't really care
let guard = hokma.write();
let cast: *const T = self.data.get().cast();

View File

@ -182,7 +182,7 @@ impl<'a> NativeCallContext<'a> {
Self {
engine,
fn_name: &context.fn_name,
source: context.source.as_ref().map(String::as_str),
source: context.source.as_deref(),
global: &context.global,
pos: context.pos,
}

View File

@ -71,6 +71,9 @@
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::negative_feature_names)]
#![allow(clippy::module_inception)]
#![allow(clippy::box_collection)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::upper_case_acronyms)]
#[cfg(feature = "no_std")]
extern crate alloc;

View File

@ -462,7 +462,7 @@ impl Module {
#[inline(always)]
pub fn set_custom_type<T>(&mut self, name: &str) -> &mut Self {
self.custom_types
.get_or_insert_with(|| CustomTypesCollection::new().into())
.get_or_insert_with(Default::default)
.add_type::<T>(name);
self
}
@ -488,7 +488,7 @@ impl Module {
name: impl Into<Identifier>,
) -> &mut Self {
self.custom_types
.get_or_insert_with(|| CustomTypesCollection::new().into())
.get_or_insert_with(Default::default)
.add(type_path, name);
self
}
@ -656,11 +656,11 @@ impl Module {
if self.is_indexed() {
let hash_var = crate::calc_var_hash(Some(""), &ident);
self.all_variables
.get_or_insert_with(|| Default::default())
.get_or_insert_with(Default::default)
.insert(hash_var, value.clone());
}
self.variables
.get_or_insert_with(|| Default::default())
.get_or_insert_with(Default::default)
.insert(ident, value);
self
}
@ -687,9 +687,7 @@ impl Module {
let hash_script = crate::calc_fn_hash(None, &fn_def.name, num_params);
#[cfg(feature = "metadata")]
let params_info = fn_def.params.iter().map(Into::into).collect();
self.functions
.get_or_insert_with(|| StraightHashMap::default().into())
.insert(
self.functions.get_or_insert_with(Default::default).insert(
hash_script,
FuncInfo {
name: fn_def.name.as_str().into(),
@ -747,7 +745,7 @@ impl Module {
self.all_type_iterators = None;
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
self.modules.get_or_insert_with(|| Default::default())
self.modules.get_or_insert_with(Default::default)
}
/// Does a sub-module exist in the [`Module`]?
@ -809,7 +807,7 @@ impl Module {
sub_module: impl Into<SharedModule>,
) -> &mut Self {
self.modules
.get_or_insert_with(|| Default::default())
.get_or_insert_with(Default::default)
.insert(name.into(), sub_module.into());
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
self
@ -1605,12 +1603,10 @@ impl Module {
#[cfg(feature = "metadata")]
if !other.doc.as_ref().map_or(true, |s| s.is_empty()) {
if !self.doc.as_ref().map_or(true, |s| s.is_empty()) {
self.doc
.get_or_insert_with(|| SmartString::new_const())
.push('\n');
self.doc.get_or_insert_with(Default::default).push('\n');
}
self.doc
.get_or_insert_with(|| SmartString::new_const())
.get_or_insert_with(Default::default)
.push_str(other.doc.as_ref().unwrap());
}
@ -1657,12 +1653,10 @@ impl Module {
#[cfg(feature = "metadata")]
if !other.doc.as_ref().map_or(true, |s| s.is_empty()) {
if !self.doc.as_ref().map_or(true, |s| s.is_empty()) {
self.doc
.get_or_insert_with(|| SmartString::new_const())
.push('\n');
self.doc.get_or_insert_with(Default::default).push('\n');
}
self.doc
.get_or_insert_with(|| SmartString::new_const())
.get_or_insert_with(Default::default)
.push_str(other.doc.as_ref().unwrap());
}
@ -1674,7 +1668,7 @@ impl Module {
#[inline]
pub fn fill_with(&mut self, other: &Self) -> &mut Self {
if let Some(ref modules) = other.modules {
let m = self.modules.get_or_insert_with(|| Default::default());
let m = self.modules.get_or_insert_with(Default::default);
for (k, v) in modules.iter() {
if !m.contains_key(k) {
@ -1684,7 +1678,7 @@ impl Module {
}
if let Some(ref variables) = other.variables {
for (k, v) in variables.iter() {
let map = self.variables.get_or_insert_with(|| Default::default());
let map = self.variables.get_or_insert_with(Default::default);
if !map.contains_key(k) {
map.insert(k.clone(), v.clone());
@ -1693,7 +1687,7 @@ impl Module {
}
if let Some(ref functions) = other.functions {
for (k, f) in functions.iter() {
let map = self.functions.get_or_insert_with(|| Default::default());
let map = self.functions.get_or_insert_with(Default::default);
if !map.contains_key(k) {
map.insert(*k, f.clone());
@ -1702,9 +1696,7 @@ impl Module {
}
self.dynamic_functions_filter += &other.dynamic_functions_filter;
if let Some(ref type_iterators) = other.type_iterators {
let t = self
.type_iterators
.get_or_insert_with(|| Default::default());
let t = self.type_iterators.get_or_insert_with(Default::default);
for (&k, v) in type_iterators.iter() {
t.entry(k).or_insert_with(|| v.clone());
@ -1718,12 +1710,10 @@ impl Module {
#[cfg(feature = "metadata")]
if !other.doc.as_ref().map_or(true, |s| s.is_empty()) {
if !self.doc.as_ref().map_or(true, |s| s.is_empty()) {
self.doc
.get_or_insert_with(|| SmartString::new_const())
.push('\n');
self.doc.get_or_insert_with(Default::default).push('\n');
}
self.doc
.get_or_insert_with(|| SmartString::new_const())
.get_or_insert_with(Default::default)
.push_str(other.doc.as_ref().unwrap());
}
@ -1797,12 +1787,10 @@ impl Module {
#[cfg(feature = "metadata")]
if !other.doc.as_ref().map_or(true, |s| s.is_empty()) {
if !self.doc.as_ref().map_or(true, |s| s.is_empty()) {
self.doc
.get_or_insert_with(|| SmartString::new_const())
.push('\n');
self.doc.get_or_insert_with(Default::default).push('\n');
}
self.doc
.get_or_insert_with(|| SmartString::new_const())
.get_or_insert_with(Default::default)
.push_str(other.doc.as_ref().unwrap());
}
@ -2285,11 +2273,11 @@ impl Module {
let func = Shared::new(func);
if self.is_indexed() {
self.all_type_iterators
.get_or_insert_with(|| Default::default())
.get_or_insert_with(Default::default)
.insert(type_id, func.clone());
}
self.type_iterators
.get_or_insert_with(|| Default::default())
.get_or_insert_with(Default::default)
.insert(type_id, func);
self
}

View File

@ -304,12 +304,12 @@ fn collect_fn_metadata(
let mut ns = SmartString::new_const();
write!(&mut ns, "{namespace}{}{name}", DoubleColon.literal_syntax()).unwrap();
scan_module(engine, list, &ns, &**m, filter);
scan_module(engine, list, &ns, m, filter);
}
}
for (ns, m) in ctx.iter_imports_raw() {
scan_module(engine, &mut list, ns, &**m, filter);
scan_module(engine, &mut list, ns, m, filter);
}
}

View File

@ -574,7 +574,7 @@ mod decimal_functions {
.into(),
)
},
|n| Ok(n),
Ok,
)
}
/// Return the integral part of the decimal number.

View File

@ -541,7 +541,7 @@ mod string_functions {
/// ```
#[rhai_fn(name = "contains")]
pub fn contains_char(string: &str, character: char) -> bool {
string.contains(character).into()
string.contains(character)
}
/// Return `true` if the string starts with a specified string.

View File

@ -201,7 +201,7 @@ impl<'e, 's> ParseState<'e, 's> {
.any(|v| v.as_str() == name)
{
self.external_vars
.get_or_insert_with(|| FnArgsVec::new().into())
.get_or_insert_with(Default::default)
.push(Ident {
name: name.into(),
pos: _pos,
@ -1659,7 +1659,7 @@ impl Engine {
}
// Access to `this` as a variable is OK within a function scope
#[cfg(not(feature = "no_function"))]
_ if &*s == KEYWORD_THIS && settings.has_flag(ParseSettingFlags::FN_SCOPE) => {
_ if *s == KEYWORD_THIS && settings.has_flag(ParseSettingFlags::FN_SCOPE) => {
Expr::Variable(
(None, ns, 0, state.get_interned_string(*s)).into(),
None,
@ -1667,7 +1667,7 @@ impl Engine {
)
}
// Cannot access to `this` as a variable not in a function scope
_ if &*s == KEYWORD_THIS => {
_ if *s == KEYWORD_THIS => {
let msg = format!("'{s}' can only be used in functions");
return Err(
LexError::ImproperSymbol(s.to_string(), msg).into_err(settings.pos)
@ -2055,7 +2055,7 @@ impl Engine {
}
// var (indexed) = rhs
Expr::Variable(ref x, i, var_pos) => {
let stack = state.stack.get_or_insert_with(|| Scope::new().into());
let stack = state.stack.get_or_insert_with(Default::default);
let (index, .., name) = &**x;
let index = i.map_or_else(
|| index.expect("either long or short index is `None`").get(),
@ -2482,7 +2482,7 @@ impl Engine {
let marker = state.get_interned_string(SCOPE_SEARCH_BARRIER_MARKER);
state
.stack
.get_or_insert_with(|| Scope::new().into())
.get_or_insert_with(Default::default)
.push(marker, ());
}
@ -2846,7 +2846,7 @@ impl Engine {
};
let prev_stack_len = {
let stack = state.stack.get_or_insert_with(|| Scope::new().into());
let stack = state.stack.get_or_insert_with(Default::default);
let prev_stack_len = stack.len();
@ -2887,7 +2887,7 @@ impl Engine {
let (name, pos) = parse_var_name(input)?;
{
let stack = state.stack.get_or_insert_with(|| Scope::new().into());
let stack = state.stack.get_or_insert_with(Default::default);
if !self.allow_shadowing() && stack.iter().any(|(v, ..)| v == name) {
return Err(PERR::VariableExists(name.into()).into_err(pos));
@ -3486,7 +3486,7 @@ impl Engine {
let name = state.get_interned_string(name);
state
.stack
.get_or_insert_with(|| Scope::new().into())
.get_or_insert_with(Default::default)
.push(name.clone(), ());
Ident { name, pos }
} else {
@ -3568,7 +3568,7 @@ impl Engine {
let s = state.get_interned_string(*s);
state
.stack
.get_or_insert_with(|| Scope::new().into())
.get_or_insert_with(Default::default)
.push(s.clone(), ());
params.push((s, pos));
}
@ -3713,7 +3713,7 @@ impl Engine {
let s = state.get_interned_string(*s);
state
.stack
.get_or_insert_with(|| Scope::new().into())
.get_or_insert_with(Default::default)
.push(s.clone(), ());
params_list.push(s);
}

View File

@ -13,7 +13,7 @@ pub struct CustomTypeInfo {
/// _(internals)_ A collection of custom types.
/// Exported under the `internals` feature only.
#[derive(Clone, Hash, Default)]
#[derive(Clone, Hash)]
pub struct CustomTypesCollection(BTreeMap<Identifier, CustomTypeInfo>);
impl fmt::Debug for CustomTypesCollection {
@ -25,6 +25,13 @@ impl fmt::Debug for CustomTypesCollection {
}
}
impl Default for CustomTypesCollection {
#[inline(always)]
fn default() -> Self {
Self::new()
}
}
impl CustomTypesCollection {
/// Create a new [`CustomTypesCollection`].
#[inline(always)]

View File

@ -1711,10 +1711,9 @@ impl Dynamic {
match self.0 {
Union::Unit(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Unit(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Unit(..))
}
_ => false,
}
}
@ -1725,10 +1724,9 @@ impl Dynamic {
match self.0 {
Union::Int(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Int(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Int(..))
}
_ => false,
}
}
@ -1742,10 +1740,9 @@ impl Dynamic {
match self.0 {
Union::Float(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Float(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Float(..))
}
_ => false,
}
}
@ -1759,10 +1756,9 @@ impl Dynamic {
match self.0 {
Union::Decimal(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Decimal(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Decimal(..))
}
_ => false,
}
}
@ -1773,10 +1769,9 @@ impl Dynamic {
match self.0 {
Union::Bool(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Bool(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Bool(..))
}
_ => false,
}
}
@ -1787,10 +1782,9 @@ impl Dynamic {
match self.0 {
Union::Char(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Char(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Char(..))
}
_ => false,
}
}
@ -1801,10 +1795,9 @@ impl Dynamic {
match self.0 {
Union::Str(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Str(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Str(..))
}
_ => false,
}
}
@ -1818,10 +1811,9 @@ impl Dynamic {
match self.0 {
Union::Array(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Array(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Array(..))
}
_ => false,
}
}
@ -1835,10 +1827,9 @@ impl Dynamic {
match self.0 {
Union::Blob(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Blob(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Blob(..))
}
_ => false,
}
}
@ -1852,10 +1843,9 @@ impl Dynamic {
match self.0 {
Union::Map(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::Map(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::Map(..))
}
_ => false,
}
}
@ -1866,10 +1856,9 @@ impl Dynamic {
match self.0 {
Union::FnPtr(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::FnPtr(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::FnPtr(..))
}
_ => false,
}
}
@ -1883,10 +1872,9 @@ impl Dynamic {
match self.0 {
Union::TimeStamp(..) => true,
#[cfg(not(feature = "no_closure"))]
Union::Shared(ref cell, ..) => match crate::func::locked_read(cell).0 {
Union::TimeStamp(..) => true,
_ => false,
},
Union::Shared(ref cell, ..) => {
matches!(crate::func::locked_read(cell).0, Union::TimeStamp(..))
}
_ => false,
}
}