From b790b525c125699b0cd976848c460e63f5df3f32 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 7 Feb 2023 22:43:48 +0000 Subject: [PATCH] Fix clippy warnings --- build/find_normal.rs | 8 ++++---- mlua_derive/src/token.rs | 2 +- src/error.rs | 32 ++++++++++++++++---------------- src/ffi/mod.rs | 19 ++++++++++--------- src/hook.rs | 4 ++-- src/lua.rs | 3 +-- src/luau.rs | 4 ++-- src/util.rs | 8 ++++---- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/build/find_normal.rs b/build/find_normal.rs index 3e72609..dd81c57 100644 --- a/build/find_normal.rs +++ b/build/find_normal.rs @@ -8,7 +8,7 @@ fn get_env_var(name: &str) -> String { match env::var(name) { Ok(val) => val, Err(env::VarError::NotPresent) => String::new(), - Err(err) => panic!("cannot get {}: {}", name, err), + Err(err) => panic!("cannot get {name}: {err}"), } } @@ -37,8 +37,8 @@ pub fn probe_lua() -> Option { if get_env_var("LUA_LINK") == "static" { link_lib = "static="; }; - println!("cargo:rustc-link-search=native={}", lib_dir); - println!("cargo:rustc-link-lib={}{}", link_lib, lua_lib); + println!("cargo:rustc-link-search=native={lib_dir}"); + println!("cargo:rustc-link-lib={link_lib}{lua_lib}"); } return Some(PathBuf::from(include_dir)); } @@ -72,7 +72,7 @@ pub fn probe_lua() -> Option { .probe(alt_probe); } - lua.unwrap_or_else(|_| panic!("cannot find Lua {} using `pkg-config`", ver)) + lua.unwrap_or_else(|_| panic!("cannot find Lua {ver} using `pkg-config`")) .include_paths .get(0) .cloned() diff --git a/mlua_derive/src/token.rs b/mlua_derive/src/token.rs index 95eba3d..1bfa6b1 100644 --- a/mlua_derive/src/token.rs +++ b/mlua_derive/src/token.rs @@ -59,7 +59,7 @@ fn parse_pos(span: &Span) -> Option<(usize, usize)> { static RE: Lazy = Lazy::new(|| Regex::new(r"bytes\(([0-9]+)\.\.([0-9]+)\)").unwrap()); - match RE.captures(&format!("{:?}", span)) { + match RE.captures(&format!("{span:?}")) { Some(caps) => match (caps.get(1), caps.get(2)) { (Some(start), Some(end)) => Some(( match start.as_str().parse() { diff --git a/src/error.rs b/src/error.rs index 71d9bfd..2c53d6c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -185,17 +185,17 @@ pub type Result = StdResult; impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { - Error::SyntaxError { ref message, .. } => write!(fmt, "syntax error: {}", message), - Error::RuntimeError(ref msg) => write!(fmt, "runtime error: {}", msg), + Error::SyntaxError { ref message, .. } => write!(fmt, "syntax error: {message}"), + Error::RuntimeError(ref msg) => write!(fmt, "runtime error: {msg}"), Error::MemoryError(ref msg) => { - write!(fmt, "memory error: {}", msg) + write!(fmt, "memory error: {msg}") } #[cfg(any(feature = "lua53", feature = "lua52"))] Error::GarbageCollectorError(ref msg) => { - write!(fmt, "garbage collector error: {}", msg) + write!(fmt, "garbage collector error: {msg}") } Error::SafetyError(ref msg) => { - write!(fmt, "safety error: {}", msg) + write!(fmt, "safety error: {msg}") }, Error::MemoryLimitNotAvailable => { write!(fmt, "setting memory limit is not available") @@ -217,17 +217,17 @@ impl fmt::Display for Error { "too many arguments to Function::bind" ), Error::ToLuaConversionError { from, to, ref message } => { - write!(fmt, "error converting {} to Lua {}", from, to)?; + write!(fmt, "error converting {from} to Lua {to}")?; match *message { None => Ok(()), - Some(ref message) => write!(fmt, " ({})", message), + Some(ref message) => write!(fmt, " ({message})"), } } Error::FromLuaConversionError { from, to, ref message } => { - write!(fmt, "error converting Lua {} to {}", from, to)?; + write!(fmt, "error converting Lua {from} to {to}")?; match *message { None => Ok(()), - Some(ref message) => write!(fmt, " ({})", message), + Some(ref message) => write!(fmt, " ({message})"), } } Error::CoroutineInactive => write!(fmt, "cannot resume inactive coroutine"), @@ -235,12 +235,12 @@ impl fmt::Display for Error { Error::UserDataDestructed => write!(fmt, "userdata has been destructed"), Error::UserDataBorrowError => write!(fmt, "userdata already mutably borrowed"), Error::UserDataBorrowMutError => write!(fmt, "userdata already borrowed"), - Error::MetaMethodRestricted(ref method) => write!(fmt, "metamethod {} is restricted", method), + Error::MetaMethodRestricted(ref method) => write!(fmt, "metamethod {method} is restricted"), Error::MetaMethodTypeError { ref method, type_name, ref message } => { - write!(fmt, "metamethod {} has unsupported type {}", method, type_name)?; + write!(fmt, "metamethod {method} has unsupported type {type_name}")?; match *message { None => Ok(()), - Some(ref message) => write!(fmt, " ({})", message), + Some(ref message) => write!(fmt, " ({message})"), } } Error::MismatchedRegistryKey => { @@ -267,20 +267,20 @@ impl fmt::Display for Error { } else { writeln!(fmt, "{}", traceback.trim_end())?; } - write!(fmt, "caused by: {}", cause) + write!(fmt, "caused by: {cause}") } Error::PreviouslyResumedPanic => { write!(fmt, "previously resumed panic returned again") } #[cfg(feature = "serialize")] Error::SerializeError(ref err) => { - write!(fmt, "serialize error: {}", err) + write!(fmt, "serialize error: {err}") }, #[cfg(feature = "serialize")] Error::DeserializeError(ref err) => { - write!(fmt, "deserialize error: {}", err) + write!(fmt, "deserialize error: {err}") }, - Error::ExternalError(ref err) => write!(fmt, "{}", err), + Error::ExternalError(ref err) => write!(fmt, "{err}"), } } } diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 41a4729..08e4183 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -73,17 +73,18 @@ pub const SYS_MIN_ALIGN: usize = 4; // by C modules in unsafe mode #[cfg(not(feature = "luau"))] pub(crate) fn keep_lua_symbols() { - let mut symbols: Vec<*const extern "C" fn()> = Vec::new(); - symbols.push(lua_atpanic as _); - symbols.push(lua_isuserdata as _); - symbols.push(lua_tocfunction as _); - symbols.push(luaL_loadstring as _); - symbols.push(luaL_openlibs as _); + let mut _symbols: Vec<*const extern "C" fn()> = vec![ + lua_atpanic as _, + lua_isuserdata as _, + lua_tocfunction as _, + luaL_loadstring as _, + luaL_openlibs as _, + ]; #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] { - symbols.push(lua_getglobal as _); - symbols.push(lua_setglobal as _); - symbols.push(luaL_setfuncs as _); + _symbols.push(lua_getglobal as _); + _symbols.push(lua_setglobal as _); + _symbols.push(luaL_setfuncs as _); } } diff --git a/src/hook.rs b/src/hook.rs index 6a0d233..c0fd762 100644 --- a/src/hook.rs +++ b/src/hook.rs @@ -162,9 +162,9 @@ impl<'lua> Debug<'lua> { #[cfg(not(feature = "luau"))] let stack = DebugStack { - num_ups: (*self.ar.get()).nups as i32, + num_ups: (*self.ar.get()).nups as _, #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] - num_params: (*self.ar.get()).nparams as i32, + num_params: (*self.ar.get()).nparams as _, #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] is_vararg: (*self.ar.get()).isvararg != 0, }; diff --git a/src/lua.rs b/src/lua.rs index 4f65ffb..26bec0e 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -3382,8 +3382,7 @@ unsafe fn ref_stack_pop(extra: &mut ExtraData) -> c_int { // It is a user error to create enough references to exhaust the Lua max stack size for // the ref thread. panic!( - "cannot create a Lua reference, out of auxiliary stack space (used {} slots)", - top + "cannot create a Lua reference, out of auxiliary stack space (used {top} slots)" ); } extra.ref_stack_size += inc; diff --git a/src/luau.rs b/src/luau.rs index 807a7f1..6ddfb5c 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -102,11 +102,11 @@ fn lua_require(lua: &Lua, name: Option) -> Result { break; } } - let source = source.ok_or_else(|| Error::RuntimeError(format!("cannot find '{}'", name)))?; + let source = source.ok_or_else(|| Error::RuntimeError(format!("cannot find '{name}'")))?; let value = lua .load(&source) - .set_name(&format!("={}", source_name)) + .set_name(&format!("={source_name}")) .set_mode(ChunkMode::Text) .call::<_, Value>(())?; diff --git a/src/util.rs b/src/util.rs index 547afe3..f736a41 100644 --- a/src/util.rs +++ b/src/util.rs @@ -844,7 +844,7 @@ pub unsafe fn init_error_registry(state: *mut ffi::lua_State) -> Result<()> { // Depending on how the API is used and what error types scripts are given, it may // be possible to make this consume arbitrary amounts of memory (for example, some // kind of recursive error structure?) - let _ = write!(&mut (*err_buf), "{}", error); + let _ = write!(&mut (*err_buf), "{error}"); Ok(err_buf) } Some(WrappedFailure::Panic(Some(ref panic))) => { @@ -855,9 +855,9 @@ pub unsafe fn init_error_registry(state: *mut ffi::lua_State) -> Result<()> { ffi::lua_pop(state, 2); if let Some(msg) = panic.downcast_ref::<&str>() { - let _ = write!(&mut (*err_buf), "{}", msg); + let _ = write!(&mut (*err_buf), "{msg}"); } else if let Some(msg) = panic.downcast_ref::() { - let _ = write!(&mut (*err_buf), "{}", msg); + let _ = write!(&mut (*err_buf), "{msg}"); } else { let _ = write!(&mut (*err_buf), ""); }; @@ -1006,7 +1006,7 @@ pub(crate) unsafe fn to_string(state: *mut ffi::lua_State, index: c_int) -> Stri let v = ffi::lua_tovector(state, index); mlua_debug_assert!(!v.is_null(), "vector is null"); let (x, y, z) = (*v, *v.add(1), *v.add(2)); - format!("vector({},{},{})", x, y, z) + format!("vector({x},{y},{z})") } ffi::LUA_TSTRING => { let mut size = 0;