Clean up more clippy.
This commit is contained in:
@@ -252,7 +252,7 @@ impl Engine {
|
||||
}
|
||||
// Standard keyword in first position but not disabled
|
||||
_ if segments.is_empty()
|
||||
&& token.as_ref().map_or(false, |v| v.is_standard_keyword())
|
||||
&& token.as_ref().map_or(false, Token::is_standard_keyword)
|
||||
&& (self.disabled_symbols.is_empty() || !self.disabled_symbols.contains(s)) =>
|
||||
{
|
||||
return Err(LexError::ImproperSymbol(
|
||||
|
@@ -291,20 +291,18 @@ impl FuncInfo {
|
||||
}
|
||||
first = false;
|
||||
|
||||
let (param_name, param_type) = self
|
||||
.metadata
|
||||
.params_info
|
||||
.get(i)
|
||||
.map(|s| {
|
||||
let mut s = s.splitn(2, ':');
|
||||
(
|
||||
s.next().unwrap_or("_").split(' ').last().unwrap(),
|
||||
s.next()
|
||||
.map(|ty| def_type_name(ty, def.engine))
|
||||
.unwrap_or(Cow::Borrowed("?")),
|
||||
)
|
||||
})
|
||||
.unwrap_or(("_", "?".into()));
|
||||
let (param_name, param_type) =
|
||||
self.metadata
|
||||
.params_info
|
||||
.get(i)
|
||||
.map_or(("_", "?".into()), |s| {
|
||||
let mut s = s.splitn(2, ':');
|
||||
(
|
||||
s.next().unwrap_or("_").split(' ').last().unwrap(),
|
||||
s.next()
|
||||
.map_or(Cow::Borrowed("?"), |ty| def_type_name(ty, def.engine)),
|
||||
)
|
||||
});
|
||||
|
||||
if operator {
|
||||
write!(writer, "{param_type}")?;
|
||||
@@ -338,8 +336,7 @@ fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> {
|
||||
let ty = ty
|
||||
.strip_prefix("RhaiResultOf<")
|
||||
.and_then(|s| s.strip_suffix('>'))
|
||||
.map(str::trim)
|
||||
.unwrap_or(ty);
|
||||
.map_or(ty, str::trim);
|
||||
|
||||
let ty = ty
|
||||
.replace("Iterator<Item=", "Iterator<")
|
||||
|
@@ -152,6 +152,7 @@ impl Engine {
|
||||
///
|
||||
/// Data types not supported by JSON serialize into formats that may invalidate the result.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn format_map_as_json(map: &Map) -> String {
|
||||
let mut result = String::from('{');
|
||||
|
||||
|
@@ -51,17 +51,20 @@ impl Engine {
|
||||
/// Is `if`-expression allowed?
|
||||
/// Default is `true`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_if_expression(&self) -> bool {
|
||||
self.options.contains(LangOptions::IF_EXPR)
|
||||
}
|
||||
/// Set whether `if`-expression is allowed.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn set_allow_if_expression(&mut self, enable: bool) {
|
||||
self.options.set(LangOptions::IF_EXPR, enable)
|
||||
self.options.set(LangOptions::IF_EXPR, enable);
|
||||
}
|
||||
/// Is `switch` expression allowed?
|
||||
/// Default is `true`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_switch_expression(&self) -> bool {
|
||||
self.options.contains(LangOptions::SWITCH_EXPR)
|
||||
}
|
||||
@@ -73,6 +76,7 @@ impl Engine {
|
||||
/// Is statement-expression allowed?
|
||||
/// Default is `true`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_statement_expression(&self) -> bool {
|
||||
self.options.contains(LangOptions::STMT_EXPR)
|
||||
}
|
||||
@@ -87,6 +91,7 @@ impl Engine {
|
||||
/// Not available under `no_function`.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_anonymous_fn(&self) -> bool {
|
||||
self.options.contains(LangOptions::ANON_FN)
|
||||
}
|
||||
@@ -101,6 +106,7 @@ impl Engine {
|
||||
/// Is looping allowed?
|
||||
/// Default is `true`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_looping(&self) -> bool {
|
||||
self.options.contains(LangOptions::LOOPING)
|
||||
}
|
||||
@@ -112,6 +118,7 @@ impl Engine {
|
||||
/// Is variables shadowing allowed?
|
||||
/// Default is `true`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn allow_shadowing(&self) -> bool {
|
||||
self.options.contains(LangOptions::SHADOW)
|
||||
}
|
||||
@@ -123,6 +130,7 @@ impl Engine {
|
||||
/// Is strict variables mode enabled?
|
||||
/// Default is `false`.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn strict_variables(&self) -> bool {
|
||||
self.options.contains(LangOptions::STRICT_VAR)
|
||||
}
|
||||
@@ -137,6 +145,7 @@ impl Engine {
|
||||
/// Not available under `no_object`.
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn fail_on_invalid_map_property(&self) -> bool {
|
||||
self.options
|
||||
.contains(LangOptions::FAIL_ON_INVALID_MAP_PROPERTY)
|
||||
|
@@ -70,7 +70,7 @@ impl Engine {
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
let param_type_names: crate::StaticVec<_> =
|
||||
param_type_names.iter().map(|ty| ty.as_str()).collect();
|
||||
param_type_names.iter().map(String::as_str).collect();
|
||||
#[cfg(feature = "metadata")]
|
||||
let param_type_names = Some(param_type_names.as_ref());
|
||||
|
||||
@@ -128,7 +128,7 @@ impl Engine {
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
let param_type_names: crate::StaticVec<_> =
|
||||
param_type_names.iter().map(|ty| ty.as_str()).collect();
|
||||
param_type_names.iter().map(String::as_str).collect();
|
||||
#[cfg(feature = "metadata")]
|
||||
let param_type_names = Some(param_type_names.as_ref());
|
||||
|
||||
@@ -989,16 +989,7 @@ impl Engine {
|
||||
let separator = crate::tokenizer::Token::DoubleColon.syntax();
|
||||
let separator = separator.as_ref();
|
||||
|
||||
if !name.contains(separator) {
|
||||
if !module.is_indexed() {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::func::shared_take_or_clone(module);
|
||||
module.build_index();
|
||||
root.insert(name.into(), module.into());
|
||||
} else {
|
||||
root.insert(name.into(), module);
|
||||
}
|
||||
} else {
|
||||
if name.contains(separator) {
|
||||
let mut iter = name.splitn(2, separator);
|
||||
let sub_module = iter.next().expect("contains separator").trim();
|
||||
let remainder = iter.next().expect("contains separator").trim();
|
||||
@@ -1015,6 +1006,13 @@ impl Engine {
|
||||
m.build_index();
|
||||
root.insert(sub_module.into(), m.into());
|
||||
}
|
||||
} else if module.is_indexed() {
|
||||
root.insert(name.into(), module);
|
||||
} else {
|
||||
// Index the module (making a clone copy if necessary) if it is not indexed
|
||||
let mut module = crate::func::shared_take_or_clone(module);
|
||||
module.build_index();
|
||||
root.insert(name.into(), module.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1039,7 +1037,7 @@ impl Engine {
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
for (name, m) in &self.global_sub_modules {
|
||||
signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f)))
|
||||
signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f)));
|
||||
}
|
||||
|
||||
signatures.extend(
|
||||
|
@@ -51,7 +51,7 @@ impl Engine {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
ast.as_ref(),
|
||||
];
|
||||
let lib = if lib.first().map(|m: &&Module| m.is_empty()).unwrap_or(true) {
|
||||
let lib = if lib.first().map_or(true, |m: &&Module| m.is_empty()) {
|
||||
&lib[0..0]
|
||||
} else {
|
||||
&lib
|
||||
|
@@ -147,10 +147,10 @@ impl Engine {
|
||||
if let Some(x) = name.strip_prefix("&mut ") {
|
||||
let r = self.format_type_name(x);
|
||||
|
||||
return if x != r {
|
||||
format!("&mut {}", r).into()
|
||||
} else {
|
||||
return if x == r {
|
||||
name.into()
|
||||
} else {
|
||||
format!("&mut {}", r).into()
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user