diff --git a/src/api/custom_syntax.rs b/src/api/custom_syntax.rs index ad7e5b40..080d4477 100644 --- a/src/api/custom_syntax.rs +++ b/src/api/custom_syntax.rs @@ -147,6 +147,7 @@ impl Expression<'_> { impl AsRef for Expression<'_> { #[inline(always)] + #[must_use] fn as_ref(&self) -> &Expr { self.0 } @@ -156,6 +157,7 @@ impl Deref for Expression<'_> { type Target = Expr; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { self.0 } diff --git a/src/api/mod.rs b/src/api/mod.rs index e9e03854..6ddf090b 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -75,6 +75,7 @@ impl Engine { /// Not available under `no_module`. #[cfg(not(feature = "no_module"))] #[inline(always)] + #[must_use] pub fn module_resolver(&self) -> &dyn crate::ModuleResolver { &*self.module_resolver } diff --git a/src/api/register.rs b/src/api/register.rs index 2b4e20ed..9095a31f 100644 --- a/src/api/register.rs +++ b/src/api/register.rs @@ -16,12 +16,14 @@ impl Engine { /// Get the global namespace module (which is the fist module in `global_modules`). #[inline(always)] #[allow(dead_code)] + #[must_use] pub(crate) fn global_namespace(&self) -> &Module { self.global_modules.first().unwrap() } /// Get a mutable reference to the global namespace module /// (which is the first module in `global_modules`). #[inline(always)] + #[must_use] pub(crate) fn global_namespace_mut(&mut self) -> &mut Module { let module = self.global_modules.first_mut().unwrap(); Shared::get_mut(module).expect("not shared") diff --git a/src/ast/ast.rs b/src/ast/ast.rs index da0454fe..902a6856 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -919,6 +919,7 @@ impl> AddAssign for AST { impl AsRef<[Stmt]> for AST { #[inline(always)] + #[must_use] fn as_ref(&self) -> &[Stmt] { self.statements() } @@ -927,6 +928,7 @@ impl AsRef<[Stmt]> for AST { #[cfg(not(feature = "no_function"))] impl AsRef for AST { #[inline(always)] + #[must_use] fn as_ref(&self) -> &crate::Module { self.shared_lib().as_ref() } @@ -935,6 +937,7 @@ impl AsRef for AST { #[cfg(not(feature = "no_function"))] impl AsRef> for AST { #[inline(always)] + #[must_use] fn as_ref(&self) -> &crate::Shared { self.shared_lib() } diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 3b07ecfd..389ac137 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -257,6 +257,7 @@ impl Hash for FloatWrapper { #[cfg(not(feature = "no_float"))] impl AsRef for FloatWrapper { #[inline(always)] + #[must_use] fn as_ref(&self) -> &F { &self.0 } @@ -265,6 +266,7 @@ impl AsRef for FloatWrapper { #[cfg(not(feature = "no_float"))] impl AsMut for FloatWrapper { #[inline(always)] + #[must_use] fn as_mut(&mut self) -> &mut F { &mut self.0 } @@ -275,6 +277,7 @@ impl Deref for FloatWrapper { type Target = F; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { &self.0 } @@ -283,6 +286,7 @@ impl Deref for FloatWrapper { #[cfg(not(feature = "no_float"))] impl DerefMut for FloatWrapper { #[inline(always)] + #[must_use] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } diff --git a/src/ast/ident.rs b/src/ast/ident.rs index 13ab4ef9..8a6d98aa 100644 --- a/src/ast/ident.rs +++ b/src/ast/ident.rs @@ -28,6 +28,7 @@ impl fmt::Debug for Ident { impl AsRef for Ident { #[inline(always)] + #[must_use] fn as_ref(&self) -> &str { self.name.as_ref() } @@ -37,6 +38,7 @@ impl Deref for Ident { type Target = ImmutableString; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { &self.name } @@ -44,6 +46,7 @@ impl Deref for Ident { impl DerefMut for Ident { #[inline(always)] + #[must_use] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.name } diff --git a/src/ast/namespace.rs b/src/ast/namespace.rs index 800dba52..9dba5b18 100644 --- a/src/ast/namespace.rs +++ b/src/ast/namespace.rs @@ -70,6 +70,7 @@ impl Deref for Namespace { type Target = StaticVec; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { &self.path } @@ -77,6 +78,7 @@ impl Deref for Namespace { impl DerefMut for Namespace { #[inline(always)] + #[must_use] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.path } diff --git a/src/ast/stmt.rs b/src/ast/stmt.rs index 68b63ecd..3b830100 100644 --- a/src/ast/stmt.rs +++ b/src/ast/stmt.rs @@ -424,6 +424,7 @@ impl Deref for StmtBlock { type Target = StmtBlockContainer; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { &self.block } @@ -431,6 +432,7 @@ impl Deref for StmtBlock { impl DerefMut for StmtBlock { #[inline(always)] + #[must_use] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.block } @@ -438,6 +440,7 @@ impl DerefMut for StmtBlock { impl AsRef<[Stmt]> for StmtBlock { #[inline(always)] + #[must_use] fn as_ref(&self) -> &[Stmt] { &self.block } @@ -445,6 +448,7 @@ impl AsRef<[Stmt]> for StmtBlock { impl AsMut<[Stmt]> for StmtBlock { #[inline(always)] + #[must_use] fn as_mut(&mut self) -> &mut [Stmt] { &mut self.block } diff --git a/src/engine.rs b/src/engine.rs index 3520108f..72f95c6b 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -240,12 +240,12 @@ impl Engine { source.map_or_else( || { if pos.is_none() { - println!("{}", s); + println!("{s}"); } else { - println!("{:?} | {}", pos, s); + println!("{pos:?} | {s}"); } }, - |source| println!("{} @ {:?} | {}", source, pos, s), + |source| println!("{source} @ {pos:?} | {s}"), ) }); } diff --git a/src/eval/target.rs b/src/eval/target.rs index 9c0804ab..3b47533d 100644 --- a/src/eval/target.rs +++ b/src/eval/target.rs @@ -399,6 +399,7 @@ impl Deref for Target<'_> { type Target = Dynamic; #[inline] + #[must_use] fn deref(&self) -> &Dynamic { match self { Self::RefMut(r) => r, @@ -416,6 +417,7 @@ impl Deref for Target<'_> { impl AsRef for Target<'_> { #[inline(always)] + #[must_use] fn as_ref(&self) -> &Dynamic { self } @@ -423,6 +425,7 @@ impl AsRef for Target<'_> { impl DerefMut for Target<'_> { #[inline] + #[must_use] fn deref_mut(&mut self) -> &mut Dynamic { match self { Self::RefMut(r) => r, @@ -440,6 +443,7 @@ impl DerefMut for Target<'_> { impl AsMut for Target<'_> { #[inline(always)] + #[must_use] fn as_mut(&mut self) -> &mut Dynamic { self } diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index ee71ce13..729e772f 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -194,8 +194,8 @@ impl FileModuleResolver { /// Get a reference to the file module resolver's [scope][Scope]. /// /// The [scope][Scope] is used for compiling module scripts. - #[must_use] #[inline(always)] + #[must_use] pub const fn scope(&self) -> &Scope { &self.scope } @@ -211,8 +211,8 @@ impl FileModuleResolver { /// Get a mutable reference to the file module resolver's [scope][Scope]. /// /// The [scope][Scope] is used for compiling module scripts. - #[must_use] #[inline(always)] + #[must_use] pub fn scope_mut(&mut self) -> &mut Scope<'static> { &mut self.scope } diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index 6823dd74..b310b302 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -252,6 +252,7 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> { type Target = T; #[inline] + #[must_use] fn deref(&self) -> &Self::Target { match self.0 { DynamicWriteLockInner::Reference(ref reference) => *reference, @@ -263,6 +264,7 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> { impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> { #[inline] + #[must_use] fn deref_mut(&mut self) -> &mut Self::Target { match self.0 { DynamicWriteLockInner::Reference(ref mut reference) => *reference, diff --git a/src/types/error.rs b/src/types/error.rs index d426d5ed..822b1a39 100644 --- a/src/types/error.rs +++ b/src/types/error.rs @@ -23,6 +23,7 @@ use std::prelude::v1::*; /// Turn on the `sync` feature to make it [`Send`] `+` [`Sync`]. #[derive(Debug)] #[non_exhaustive] +#[must_use] pub enum EvalAltResult { /// System error. Wrapped values are the error message and the internal error. #[cfg(not(feature = "sync"))] @@ -494,6 +495,7 @@ impl EvalAltResult { /// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards. #[cold] #[inline(never)] + #[must_use] pub fn take_position(&mut self) -> Position { let pos = self.position(); self.set_position(Position::NONE); diff --git a/src/types/immutable_string.rs b/src/types/immutable_string.rs index 6487efeb..507c33d6 100644 --- a/src/types/immutable_string.rs +++ b/src/types/immutable_string.rs @@ -53,6 +53,7 @@ impl Deref for ImmutableString { type Target = SmartString; #[inline(always)] + #[must_use] fn deref(&self) -> &Self::Target { &self.0 } @@ -60,6 +61,7 @@ impl Deref for ImmutableString { impl AsRef for ImmutableString { #[inline(always)] + #[must_use] fn as_ref(&self) -> &SmartString { &self.0 } @@ -67,6 +69,7 @@ impl AsRef for ImmutableString { impl AsRef for ImmutableString { #[inline(always)] + #[must_use] fn as_ref(&self) -> &str { &self.0 } @@ -74,6 +77,7 @@ impl AsRef for ImmutableString { impl Borrow for ImmutableString { #[inline(always)] + #[must_use] fn borrow(&self) -> &SmartString { &self.0 } @@ -81,6 +85,7 @@ impl Borrow for ImmutableString { impl Borrow for ImmutableString { #[inline(always)] + #[must_use] fn borrow(&self) -> &str { self.as_str() } @@ -623,7 +628,7 @@ impl ImmutableString { #[inline] #[must_use] pub fn into_owned(mut self) -> String { - self.make_mut(); // Make sure it is unique reference + let _ = self.make_mut(); // Make sure it is unique reference shared_take(self.0).into() // Should succeed } /// Make sure that the [`ImmutableString`] is unique (i.e. no other outstanding references). @@ -631,6 +636,7 @@ impl ImmutableString { /// /// If there are other references to the same string, a cloned copy is used. #[inline(always)] + #[must_use] pub(crate) fn make_mut(&mut self) -> &mut SmartString { shared_make_mut(&mut self.0) } diff --git a/src/types/parse_error.rs b/src/types/parse_error.rs index 5cbdcb5d..e9b55ce3 100644 --- a/src/types/parse_error.rs +++ b/src/types/parse_error.rs @@ -13,6 +13,7 @@ use std::prelude::v1::*; /// Error encountered when tokenizing the script text. #[derive(Debug, Eq, PartialEq, Clone, Hash)] #[non_exhaustive] +#[must_use] pub enum LexError { /// An unexpected symbol is encountered when tokenizing the script text. UnexpectedInput(String), @@ -58,8 +59,8 @@ impl fmt::Display for LexError { impl LexError { /// Convert a [`LexError`] into a [`ParseError`]. - #[inline(always)] - #[must_use] + #[cold] + #[inline(never)] pub fn into_err(self, pos: Position) -> ParseError { ParseError(Box::new(self.into()), pos) } @@ -72,6 +73,7 @@ impl LexError { /// massive code changes to remove/add back enum variants in match statements. #[derive(Debug, Eq, PartialEq, Clone, Hash)] #[non_exhaustive] +#[must_use] pub enum ParseErrorType { /// The script ends prematurely. UnexpectedEOF, @@ -171,7 +173,8 @@ pub enum ParseErrorType { impl ParseErrorType { /// Make a [`ParseError`] using the current type and position. - #[inline(always)] + #[cold] + #[inline(never)] #[must_use] pub(crate) fn into_err(self, pos: Position) -> ParseError { ParseError(self.into(), pos) @@ -277,6 +280,7 @@ impl From for ParseErrorType { /// Error when parsing a script. #[derive(Debug, Eq, PartialEq, Clone, Hash)] +#[must_use] pub struct ParseError( /// Parse error type. pub Box, diff --git a/tests/operations.rs b/tests/operations.rs index d6b7b69f..c4eb37ab 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -10,7 +10,7 @@ fn test_max_operations() -> Result<(), Box> { engine.on_progress(|count| { if count % 100 == 0 { - println!("{}", count); + println!("{count}"); } None }); @@ -68,7 +68,7 @@ fn test_max_operations_functions() -> Result<(), Box> { engine.on_progress(|count| { if count % 100 == 0 { - println!("{}", count); + println!("{count}"); } None }); @@ -124,7 +124,7 @@ fn test_max_operations_eval() -> Result<(), Box> { engine.on_progress(|count| { if count % 100 == 0 { - println!("{}", count); + println!("{count}"); } None }); diff --git a/tests/plugins.rs b/tests/plugins.rs index d5072eb9..5fe58fdc 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -42,7 +42,7 @@ mod test { #[rhai_fn(name = "no_effect", set = "no_effect", pure)] pub fn no_effect(array: &mut Array, value: INT) { // array is not modified - println!("Array = {:?}, Value = {}", array, value); + println!("Array = {array:?}, Value = {value}"); } } } diff --git a/tests/print.rs b/tests/print.rs index 820cce58..982b2ff2 100644 --- a/tests/print.rs +++ b/tests/print.rs @@ -66,7 +66,7 @@ fn test_print_debug() -> Result<(), Box> { ); for entry in logbook.read().unwrap().iter() { - println!("{}", entry); + println!("{entry}"); } Ok(()) diff --git a/tests/serde.rs b/tests/serde.rs index 5df11139..45c16b72 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -820,6 +820,6 @@ fn test_serde_blob() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] fn test_serde_json_borrowed_string() { let value = json!({ "a": "b" }); - println!("value: {:?}", value); + println!("value: {value:?}"); let _: Dynamic = serde_json::from_value(value).unwrap(); } diff --git a/tests/var_scope.rs b/tests/var_scope.rs index 73701746..e249b6de 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -140,7 +140,7 @@ fn test_scope_eval() -> Result<(), Box> { // Second invocation using the same state let result = engine.eval_with_scope::(&mut scope, "x")?; - println!("result: {}", result); // should print 966 + println!("result: {result}"); // should print 966 // Variable y is changed in the script assert_eq!(