Skip to content

Commit ddc61bf

Browse files
committed
Fix some clippy warnings & minor changes
1 parent 7a16f3d commit ddc61bf

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/ffi/compat53.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ end
250250

251251
#[cfg(any(feature = "lua51", feature = "luajit"))]
252252
pub unsafe fn lua_arith(L: *mut lua_State, op: c_int) {
253+
#[allow(clippy::manual_range_contains)]
253254
if op < LUA_OPADD || op > LUA_OPUNM {
254255
luaL_error(L, cstr!("invalid 'op' argument for lua_arith"));
255256
}

src/lua.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ impl Lua {
15451545
let mut extra_tables_count = 0;
15461546

15471547
let mut field_getters_index = None;
1548-
let has_field_getters = fields.field_getters.len() > 0;
1548+
let has_field_getters = !fields.field_getters.is_empty();
15491549
if has_field_getters {
15501550
protect_lua_closure(self.state, 0, 1, |state| {
15511551
ffi::lua_newtable(state);
@@ -1563,7 +1563,7 @@ impl Lua {
15631563
}
15641564

15651565
let mut field_setters_index = None;
1566-
let has_field_setters = fields.field_setters.len() > 0;
1566+
let has_field_setters = !fields.field_setters.is_empty();
15671567
if has_field_setters {
15681568
protect_lua_closure(self.state, 0, 1, |state| {
15691569
ffi::lua_newtable(state);
@@ -1582,9 +1582,9 @@ impl Lua {
15821582

15831583
let mut methods_index = None;
15841584
#[cfg(feature = "async")]
1585-
let has_methods = methods.methods.len() > 0 || methods.async_methods.len() > 0;
1585+
let has_methods = !methods.methods.is_empty() || !methods.async_methods.is_empty();
15861586
#[cfg(not(feature = "async"))]
1587-
let has_methods = methods.methods.len() > 0;
1587+
let has_methods = !methods.methods.is_empty();
15881588
if has_methods {
15891589
protect_lua_closure(self.state, 0, 1, |state| {
15901590
ffi::lua_newtable(state);
@@ -2516,6 +2516,7 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> {
25162516
struct StaticUserDataFields<'lua, T: 'static + UserData> {
25172517
field_getters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
25182518
field_setters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
2519+
#[allow(clippy::type_complexity)]
25192520
meta_fields: Vec<(
25202521
MetaMethod,
25212522
Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>> + 'static>,

src/scope.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
258258
if ffi::lua_getmetatable(lua.state, -1) == 0 {
259259
return Err(Error::UserDataTypeMismatch);
260260
}
261-
ffi::lua_pushstring(lua.state, cstr!("__mlua"));
261+
ffi::lua_pushstring(lua.state, cstr!("__mlua_ptr"));
262262
if ffi::lua_rawget(lua.state, -2) == ffi::LUA_TLIGHTUSERDATA {
263263
let ud_ptr = ffi::lua_touserdata(lua.state, -1);
264264
if ud_ptr == check_data.as_ptr() as *mut c_void {
@@ -329,7 +329,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
329329
ffi::lua_newtable(state);
330330

331331
// Add internal metamethod to store reference to the data
332-
ffi::lua_pushstring(state, cstr!("__mlua"));
332+
ffi::lua_pushstring(state, cstr!("__mlua_ptr"));
333333
ffi::lua_pushlightuserdata(lua.state, data.as_ptr() as *mut c_void);
334334
ffi::lua_rawset(state, -3);
335335
})?;
@@ -352,7 +352,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
352352
let metatable_index = ffi::lua_absindex(lua.state, -1);
353353

354354
let mut field_getters_index = None;
355-
if ud_fields.field_getters.len() > 0 {
355+
if !ud_fields.field_getters.is_empty() {
356356
protect_lua_closure(lua.state, 0, 1, |state| {
357357
ffi::lua_newtable(state);
358358
})?;
@@ -368,7 +368,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
368368
}
369369

370370
let mut field_setters_index = None;
371-
if ud_fields.field_setters.len() > 0 {
371+
if !ud_fields.field_setters.is_empty() {
372372
protect_lua_closure(lua.state, 0, 1, |state| {
373373
ffi::lua_newtable(state);
374374
})?;
@@ -384,7 +384,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
384384
}
385385

386386
let mut methods_index = None;
387-
if ud_methods.methods.len() > 0 {
387+
if !ud_methods.methods.is_empty() {
388388
// Create table used for methods lookup
389389
protect_lua_closure(lua.state, 0, 1, |state| {
390390
ffi::lua_newtable(state);
@@ -430,7 +430,8 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
430430

431431
// We know the destructor has not run yet because we hold a reference to the
432432
// userdata.
433-
vec![Box::new(take_userdata::<()>(state))]
433+
take_userdata::<()>(state);
434+
vec![]
434435
}));
435436

436437
Ok(ud)
@@ -730,6 +731,7 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> for NonStaticUserDataMethods<'l
730731
struct NonStaticUserDataFields<'lua, T: UserData> {
731732
field_getters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
732733
field_setters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
734+
#[allow(clippy::type_complexity)]
733735
meta_fields: Vec<(MetaMethod, Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>>>)>,
734736
}
735737

src/userdata.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ impl MetaMethod {
187187
MetaMethod::Custom(name) if name == "__metatable" => {
188188
Err(Error::MetaMethodRestricted(name))
189189
}
190-
MetaMethod::Custom(name) if name == "__mlua" => Err(Error::MetaMethodRestricted(name)),
190+
MetaMethod::Custom(name) if name.starts_with("__mlua") => {
191+
Err(Error::MetaMethodRestricted(name))
192+
}
191193
_ => Ok(self),
192194
}
193195
}
@@ -714,7 +716,9 @@ impl<'lua> AnyUserData<'lua> {
714716
/// Returns a metatable of this `UserData`.
715717
///
716718
/// Returned [`UserDataMetatable`] object wraps the original metatable and
717-
/// allows to provide safe access to it methods.
719+
/// provides safe access to it methods.
720+
///
721+
/// For `T: UserData + 'static` returned metatable is shared among all instances of type `T`.
718722
///
719723
/// [`UserDataMetatable`]: struct.UserDataMetatable.html
720724
pub fn get_metatable(&self) -> Result<UserDataMetatable<'lua>> {

0 commit comments

Comments
 (0)