Refine #[must_use]

This commit is contained in:
Stephen Chung
2022-11-28 16:36:40 +08:00
parent f458f18ffa
commit 29a397b216
11 changed files with 49 additions and 50 deletions

View File

@@ -599,13 +599,15 @@ impl Engine {
// Try to call index setter if value is changed
let idx = &mut idx_val_for_setter;
let new_val = &mut new_val;
self.call_indexer_set(
global, caches, target, idx, new_val, is_ref_mut, op_pos,
)
.or_else(|e| match *e {
ERR::ErrorIndexingType(..) => Ok((Dynamic::UNIT, false)),
_ => Err(e),
})?;
// The return value of a indexer setter (usually `()`) is thrown away and not used.
let _ = self
.call_indexer_set(
global, caches, target, idx, new_val, is_ref_mut, op_pos,
)
.or_else(|e| match *e {
ERR::ErrorIndexingType(..) => Ok((Dynamic::UNIT, false)),
_ => Err(e),
})?;
}
Ok(result)
@@ -659,8 +661,8 @@ impl Engine {
// Try to call index setter
let new_val = &mut new_val;
self.call_indexer_set(
// The return value of a indexer setter (usually `()`) is thrown away and not used.
let _ = self.call_indexer_set(
global, caches, target, idx_val, new_val, is_ref_mut, op_pos,
)?;
}
@@ -981,18 +983,19 @@ impl Engine {
// Re-use args because the first &mut parameter will not be consumed
let mut arg_values = [target.as_mut(), val.as_mut()];
let args = &mut arg_values;
self.exec_native_fn_call(
global,
caches,
setter,
Token::NonToken,
*hash_set,
args,
is_ref_mut,
pos,
)
.or_else(
|err| match *err {
// The return value is thrown away and not used.
let _ = self
.exec_native_fn_call(
global,
caches,
setter,
Token::NonToken,
*hash_set,
args,
is_ref_mut,
pos,
)
.or_else(|err| match *err {
// Try an indexer if property does not exist
ERR::ErrorDotExpr(..) => {
let idx = &mut name.into();
@@ -1011,8 +1014,7 @@ impl Engine {
})
}
_ => Err(err),
},
)?;
})?;
}
Ok((result, may_be_changed))

View File

@@ -81,6 +81,7 @@ pub fn calc_index<E>(
/// A type that encapsulates a mutation target for an expression with side effects.
#[derive(Debug)]
#[must_use]
pub enum Target<'a> {
/// The target is a mutable reference to a [`Dynamic`].
RefMut(&'a mut Dynamic),
@@ -195,7 +196,6 @@ impl<'a> Target<'a> {
}
/// Get the value of the [`Target`] as a [`Dynamic`], cloning a referenced value if necessary.
#[inline]
#[must_use]
pub fn take_or_clone(self) -> Dynamic {
match self {
Self::RefMut(r) => r.clone(), // Referenced value is cloned
@@ -223,7 +223,6 @@ impl<'a> Target<'a> {
}
/// Convert a shared or reference [`Target`] into a target with an owned value.
#[inline(always)]
#[must_use]
pub fn into_owned(self) -> Self {
match self {
Self::RefMut(r) => Self::TempValue(r.clone()),
@@ -437,7 +436,6 @@ impl AsMut<Dynamic> for Target<'_> {
impl<T: Into<Dynamic>> From<T> for Target<'_> {
#[inline(always)]
#[must_use]
fn from(value: T) -> Self {
Self::TempValue(value.into())
}