Skip to content

Commit de25d51

Browse files
committed
Clippy fixes
1 parent 66b9f08 commit de25d51

17 files changed

Lines changed: 53 additions & 77 deletions

examples/async_http_client.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +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();
16+
if let Some(bytes) = reader.0.frame().await
17+
&& let Some(bytes) = bytes.into_lua_err()?.data_ref() {
18+
return Some(lua.create_string(bytes)).transpose();
1919
}
20-
}
2120
Ok(None)
2221
});
2322
}

examples/guided_tour.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() -> Result<()> {
3535
assert_eq!(globals.get::<String>("global")?, "foobar");
3636

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

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

122-
assert_eq!(
122+
assert!(
123123
lua.load(r#"check_equal({"a", "b", "c"}, {"a", "b", "c"})"#)
124-
.eval::<bool>()?,
125-
true
124+
.eval::<bool>()?
126125
);
127-
assert_eq!(
128-
lua.load(r#"check_equal({"a", "b", "c"}, {"d", "e", "f"})"#)
129-
.eval::<bool>()?,
130-
false
126+
assert!(
127+
!lua.load(r#"check_equal({"a", "b", "c"}, {"d", "e", "f"})"#)
128+
.eval::<bool>()?
131129
);
132130
assert_eq!(lua.load(r#"join("a", "b", "c")"#).eval::<String>()?, "abc");
133131

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/state/raw.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,10 @@ 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 {
404+
if status == ffi::LUA_OK
405+
&& (*self.extra.get()).enable_jit && ffi::luau_codegen_supported() != 0 {
406406
ffi::luau_codegen_compile(state, -1);
407407
}
408-
}
409408
status
410409
}
411410

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ 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())).eval::<i32>()?,
5454
321
5555
);
5656

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

6464
// StdString
6565
assert_eq!(lua.load(String::from("1")).eval::<i32>()?, 1);
66-
assert_eq!(lua.load(&String::from("2")).eval::<i32>()?, 2);
66+
assert_eq!(lua.load(String::from("2")).eval::<i32>()?, 2);
6767

6868
// &[u8]
6969
assert_eq!(lua.load(&b"3"[..]).eval::<i32>()?, 3);
7070

7171
// Vec<u8>
7272
assert_eq!(lua.load(b"4".to_vec()).eval::<i32>()?, 4);
73-
assert_eq!(lua.load(&b"5".to_vec()).eval::<i32>()?, 5);
73+
assert_eq!(lua.load(b"5".to_vec()).eval::<i32>()?, 5);
7474

7575
Ok(())
7676
}
@@ -172,7 +172,7 @@ fn test_compiler_library_constants() {
172172
let lua = Lua::new();
173173
lua.set_compiler(compiler);
174174
let const_bool = lua.load("return mylib.const_bool").eval::<bool>().unwrap();
175-
assert_eq!(const_bool, true);
175+
assert!(const_bool);
176176
let const_num = lua.load("return mylib.const_num").eval::<f64>().unwrap();
177177
assert_eq!(const_num, 123.0);
178178
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
}

tests/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn test_error_context() -> Result<()> {
3333

3434
// Rewrite context message and test `downcast_ref`
3535
let func3 = lua.create_function(|_, ()| {
36-
Err::<(), _>(Error::external(io::Error::new(io::ErrorKind::Other, "other")))
36+
Err::<(), _>(Error::external(io::Error::other("other")))
3737
.context("some context")
3838
.context("some new context")
3939
})?;
@@ -52,11 +52,11 @@ fn test_error_chain() -> Result<()> {
5252
let lua = Lua::new();
5353

5454
// Check that `Error::ExternalError` creates a chain with a single element
55-
let io_err = io::Error::new(io::ErrorKind::Other, "other");
55+
let io_err = io::Error::other("other");
5656
assert_eq!(Error::external(io_err).chain().count(), 1);
5757

5858
let func = lua.create_function(|_, ()| {
59-
let err = Error::external(io::Error::new(io::ErrorKind::Other, "other")).context("io error");
59+
let err = Error::external(io::Error::other("other")).context("io error");
6060
Err::<(), _>(err)
6161
})?;
6262
let err = func.call::<()>(()).unwrap_err();

tests/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn test_function_info() -> Result<()> {
213213
let func_with_upvalues_info = func_with_upvalues.info();
214214
assert_eq!(func_with_upvalues_info.num_upvalues, 2);
215215
assert_eq!(func_with_upvalues_info.num_params, 1);
216-
assert_eq!(func_with_upvalues_info.is_vararg, true);
216+
assert!(func_with_upvalues_info.is_vararg);
217217
}
218218

219219
Ok(())
@@ -227,7 +227,7 @@ fn test_function_dump() -> Result<()> {
227227
let concat_lua = lua
228228
.load(r#"function(arg1, arg2) return arg1 .. arg2 end"#)
229229
.eval::<Function>()?;
230-
let concat = lua.load(&concat_lua.dump(false)).into_function()?;
230+
let concat = lua.load(concat_lua.dump(false)).into_function()?;
231231

232232
assert_eq!(concat.call::<String>(("foo", "bar"))?, "foobar");
233233

@@ -417,7 +417,7 @@ fn test_function_wrap() -> Result<()> {
417417
// Check recursive mut callback error
418418
let fmut = Function::wrap_mut(|f: Function| match f.call::<()>(&f) {
419419
Err(Error::CallbackError { cause, .. }) => match cause.as_ref() {
420-
Error::RecursiveMutCallback { .. } => Ok::<_, Error>(()),
420+
Error::RecursiveMutCallback => Ok::<_, Error>(()),
421421
other => panic!("incorrect result: {other:?}"),
422422
},
423423
other => panic!("incorrect result: {other:?}"),

0 commit comments

Comments
 (0)