Skip to content

Commit 5a7ad9f

Browse files
committed
Fix some clippy warnings & minor changes
1 parent decb5b9 commit 5a7ad9f

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
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
@@ -1557,7 +1557,7 @@ impl Lua {
15571557
let mut extra_tables_count = 0;
15581558

15591559
let mut field_getters_index = None;
1560-
let has_field_getters = fields.field_getters.len() > 0;
1560+
let has_field_getters = !fields.field_getters.is_empty();
15611561
if has_field_getters {
15621562
protect_lua_closure(self.state, 0, 1, |state| {
15631563
ffi::lua_newtable(state);
@@ -1575,7 +1575,7 @@ impl Lua {
15751575
}
15761576

15771577
let mut field_setters_index = None;
1578-
let has_field_setters = fields.field_setters.len() > 0;
1578+
let has_field_setters = !fields.field_setters.is_empty();
15791579
if has_field_setters {
15801580
protect_lua_closure(self.state, 0, 1, |state| {
15811581
ffi::lua_newtable(state);
@@ -1594,9 +1594,9 @@ impl Lua {
15941594

15951595
let mut methods_index = None;
15961596
#[cfg(feature = "async")]
1597-
let has_methods = methods.methods.len() > 0 || methods.async_methods.len() > 0;
1597+
let has_methods = !methods.methods.is_empty() || !methods.async_methods.is_empty();
15981598
#[cfg(not(feature = "async"))]
1599-
let has_methods = methods.methods.len() > 0;
1599+
let has_methods = !methods.methods.is_empty();
16001600
if has_methods {
16011601
protect_lua_closure(self.state, 0, 1, |state| {
16021602
ffi::lua_newtable(state);
@@ -2546,6 +2546,7 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> {
25462546
struct StaticUserDataFields<'lua, T: 'static + UserData> {
25472547
field_getters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
25482548
field_setters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
2549+
#[allow(clippy::type_complexity)]
25492550
meta_fields: Vec<(
25502551
MetaMethod,
25512552
Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>> + 'static>,

src/scope.rs

Lines changed: 6 additions & 5 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 {
@@ -330,7 +330,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
330330
ffi::lua_newtable(state);
331331

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

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

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

387387
let mut methods_index = None;
388-
if ud_methods.methods.len() > 0 {
388+
if !ud_methods.methods.is_empty() {
389389
// Create table used for methods lookup
390390
protect_lua_closure(lua.state, 0, 1, |state| {
391391
ffi::lua_newtable(state);
@@ -738,6 +738,7 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> for NonStaticUserDataMethods<'l
738738
struct NonStaticUserDataFields<'lua, T: UserData> {
739739
field_getters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
740740
field_setters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
741+
#[allow(clippy::type_complexity)]
741742
meta_fields: Vec<(MetaMethod, Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>>>)>,
742743
}
743744

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)