Skip to content

Commit 4bca98f

Browse files
committed
clippy
1 parent 87dc0c1 commit 4bca98f

19 files changed

Lines changed: 86 additions & 88 deletions

examples/async_http_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ impl UserData for BodyReader {
1313
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
1414
// Every call returns a next chunk
1515
methods.add_async_method_mut("read", |lua, mut reader, ()| async move {
16-
if let Some(bytes) = reader.0.frame().await {
17-
if let Some(bytes) = bytes.into_lua_err()?.data_ref() {
18-
return Some(lua.create_string(&bytes)).transpose();
19-
}
16+
if let Some(bytes) = reader.0.frame().await
17+
&& let Some(bytes) = bytes.into_lua_err()?.data_ref()
18+
{
19+
return Some(lua.create_string(bytes)).transpose();
2020
}
2121
Ok(None)
2222
});

examples/guided_tour.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::f32;
21
use std::iter::FromIterator;
32

43
use mlua::{FromLua, Function, Lua, MetaMethod, Result, UserData, UserDataMethods, Value, Variadic, chunk};
@@ -35,7 +34,7 @@ fn main() -> Result<()> {
3534
assert_eq!(globals.get::<String>("global")?, "foobar");
3635

3736
assert_eq!(lua.load("1 + 1").eval::<i32>()?, 2);
38-
assert_eq!(lua.load("false == false").eval::<bool>()?, true);
37+
assert!(lua.load("false == false").eval::<bool>()?);
3938
assert_eq!(lua.load("return 1 + 2").eval::<i32>()?, 3);
4039

4140
// Use can use special `chunk!` macro to use Rust tokenizer and automatically capture variables
@@ -119,15 +118,13 @@ fn main() -> Result<()> {
119118
})?;
120119
globals.set("join", join)?;
121120

122-
assert_eq!(
121+
assert!(
123122
lua.load(r#"check_equal({"a", "b", "c"}, {"a", "b", "c"})"#)
124-
.eval::<bool>()?,
125-
true
123+
.eval::<bool>()?
126124
);
127-
assert_eq!(
128-
lua.load(r#"check_equal({"a", "b", "c"}, {"d", "e", "f"})"#)
129-
.eval::<bool>()?,
130-
false
125+
assert!(
126+
!lua.load(r#"check_equal({"a", "b", "c"}, {"d", "e", "f"})"#)
127+
.eval::<bool>()?
131128
);
132129
assert_eq!(lua.load(r#"join("a", "b", "c")"#).eval::<String>()?, "abc");
133130

examples/repl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
match lua.load(&line).eval::<MultiValue>() {
2121
Ok(values) => {
2222
editor.add_history_entry(line).unwrap();
23-
if values.len() > 0 {
23+
if !values.is_empty() {
2424
println!(
2525
"{}",
2626
values
@@ -37,7 +37,7 @@ fn main() {
3737
..
3838
}) => {
3939
// continue reading input and append it to `line`
40-
line.push_str("\n"); // separate input lines
40+
line.push('\n'); // separate input lines
4141
prompt = ">> ";
4242
}
4343
Err(e) => {

src/luau/heap_dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn update_size<K: Eq + Hash>(size_type: &mut HashMap<K, (usize, u64)>, key: K, s
168168
/// Retrieves the value associated with a given `key` from a Lua table `tbl`.
169169
fn get_key<'a>(objects: &'a HashMap<&'a str, Json>, tbl: &Json, key: &str) -> Option<&'a str> {
170170
let pairs = tbl["pairs"].as_array()?;
171-
for kv in pairs.chunks_exact(2) {
171+
for kv in pairs.as_chunks::<2>().0 {
172172
#[rustfmt::skip]
173173
let (Some(key_addr), Some(val_addr)) = (kv[0].as_str(), kv[1].as_str()) else { continue; };
174174
if objects[key_addr]["type"] == "string" && objects[key_addr]["data"].as_str() == Some(key) {

src/luau/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ mod tests {
263263
fn test_numbers() {
264264
assert_eq!(parse("0").unwrap(), Json::Integer(0));
265265
assert_eq!(parse("-42").unwrap(), Json::Integer(-42));
266-
assert_eq!(parse("3.14").unwrap(), Json::Number(3.14));
267-
assert_eq!(parse("-3.14").unwrap(), Json::Number(-3.14));
266+
assert_eq!(parse("3.25").unwrap(), Json::Number(3.25));
267+
assert_eq!(parse("-3.25").unwrap(), Json::Number(-3.25));
268268
assert_eq!(parse("1e10").unwrap(), Json::Number(1e10));
269269
assert_eq!(parse("1E10").unwrap(), Json::Number(1E10));
270270
assert_eq!(parse("1e-10").unwrap(), Json::Number(1e-10));

src/state/raw.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,8 @@ impl RawLua {
401401
},
402402
);
403403
#[cfg(feature = "luau-jit")]
404-
if status == ffi::LUA_OK {
405-
if (*self.extra.get()).enable_jit && ffi::luau_codegen_supported() != 0 {
406-
ffi::luau_codegen_compile(state, -1);
407-
}
404+
if status == ffi::LUA_OK && (*self.extra.get()).enable_jit && ffi::luau_codegen_supported() != 0 {
405+
ffi::luau_codegen_compile(state, -1);
408406
}
409407
status
410408
}

tests/async.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async fn test_async_call() -> Result<()> {
120120
assert_eq!(hello.call_async::<String>("alex").await?, "hello, alex!");
121121

122122
// Executing non-async functions using async call is allowed
123-
let sum = lua.create_function(|_lua, (a, b): (i64, i64)| return Ok(a + b))?;
123+
let sum = lua.create_function(|_lua, (a, b): (i64, i64)| Ok(a + b))?;
124124
assert_eq!(sum.call_async::<i64>((5, 1)).await?, 6);
125125

126126
Ok(())
@@ -230,7 +230,7 @@ async fn test_async_return_async_closure() -> Result<()> {
230230

231231
let g = lua.create_async_function(move |_, b: i64| async move {
232232
sleep_ms(10).await;
233-
return Ok(a + b);
233+
Ok(a + b)
234234
})?;
235235

236236
Ok(g)

tests/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn test_buffer() -> Result<()> {
2525

2626
// Check that we can pass buffer type to Lua
2727
let buf1 = buf1.as_buffer().unwrap();
28-
let func = lua.create_function(|_, buf: Value| return buf.to_string())?;
28+
let func = lua.create_function(|_, buf: Value| buf.to_string())?;
2929
assert!(func.call::<String>(buf1)?.starts_with("buffer:"));
3030

3131
// Check buffer methods

tests/chunk.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ fn test_chunk_path() -> Result<()> {
5050

5151
// &Path
5252
assert_eq!(
53-
(lua.load(&*temp_dir.path().join("module.lua").as_path())).eval::<i32>()?,
53+
lua.load(temp_dir.path().join("module.lua").as_path())
54+
.eval::<i32>()?,
5455
321
5556
);
5657

@@ -63,14 +64,14 @@ fn test_chunk_impls() -> Result<()> {
6364

6465
// StdString
6566
assert_eq!(lua.load(String::from("1")).eval::<i32>()?, 1);
66-
assert_eq!(lua.load(&String::from("2")).eval::<i32>()?, 2);
67+
assert_eq!(lua.load(String::from("2")).eval::<i32>()?, 2);
6768

6869
// &[u8]
6970
assert_eq!(lua.load(&b"3"[..]).eval::<i32>()?, 3);
7071

7172
// Vec<u8>
7273
assert_eq!(lua.load(b"4".to_vec()).eval::<i32>()?, 4);
73-
assert_eq!(lua.load(&b"5".to_vec()).eval::<i32>()?, 5);
74+
assert_eq!(lua.load(b"5".to_vec()).eval::<i32>()?, 5);
7475

7576
Ok(())
7677
}
@@ -172,7 +173,7 @@ fn test_compiler_library_constants() {
172173
let lua = Lua::new();
173174
lua.set_compiler(compiler);
174175
let const_bool = lua.load("return mylib.const_bool").eval::<bool>().unwrap();
175-
assert_eq!(const_bool, true);
176+
assert!(const_bool);
176177
let const_num = lua.load("return mylib.const_num").eval::<f64>().unwrap();
177178
assert_eq!(const_num, 123.0);
178179
let const_vec = lua.load("return mylib.const_vec").eval::<Vector>().unwrap();

tests/conversion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn test_bool_into_lua() -> Result<()> {
313313
// Push into stack
314314
let table = lua.create_table()?;
315315
table.set("b", true)?;
316-
assert_eq!(true, table.get::<bool>("b")?);
316+
assert!(table.get::<bool>("b")?);
317317

318318
Ok(())
319319
}

0 commit comments

Comments
 (0)