diff --git a/libclamav_rust/build.rs b/libclamav_rust/build.rs index beee20d132..f71ca8e9a3 100644 --- a/libclamav_rust/build.rs +++ b/libclamav_rust/build.rs @@ -160,7 +160,7 @@ fn execute_bindgen() -> Result<(), &'static str> { /// Use cbindgen to generate C-header's for Rust static libraries. fn execute_cbindgen() -> Result<(), &'static str> { let crate_dir = env::var("CARGO_MANIFEST_DIR").or(Err("CARGO_MANIFEST_DIR not specified"))?; - let build_dir = PathBuf::from(env::var("CARGO_TARGET_DIR").unwrap_or(".".into())); + let build_dir = PathBuf::from(env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| ".".into())); let outfile_path = build_dir.join(C_HEADER_OUTPUT); // Useful for build diagnostics @@ -234,7 +234,7 @@ fn search_and_link_lib(environment_variable: &str) -> Result eprintln!(" - requesting that rustc link {:?}", &parsed_path.libname); println!("cargo:rustc-link-lib={}", parsed_path.libname); - return Ok(true); + Ok(true) } struct ParsedLibraryPath { @@ -255,7 +255,7 @@ fn parse_lib_path<'a>(path: &'a str) -> Result // This can't fail because it came from a &str let dir = path .parent() - .unwrap_or(Path::new(".")) + .unwrap_or_else(|| Path::new(".")) .to_str() .unwrap() .to_owned(); diff --git a/libclamav_rust/src/cdiff.rs b/libclamav_rust/src/cdiff.rs index f8d3383c0b..8c3386cf5b 100644 --- a/libclamav_rust/src/cdiff.rs +++ b/libclamav_rust/src/cdiff.rs @@ -185,11 +185,9 @@ impl<'a> DelOp<'a> { Ok(DelOp { line_no: iter .next() - .ok_or_else(|| CdiffError::NoMoreData("line_no"))? + .ok_or(CdiffError::NoMoreData("line_no"))? .parse::()?, - del_line: iter - .next() - .ok_or_else(|| CdiffError::NoMoreData("del_line"))?, + del_line: iter.next().ok_or(CdiffError::NoMoreData("del_line"))?, }) } } @@ -210,22 +208,18 @@ impl<'a> MoveOp<'a> { let mut iter = data.split_whitespace(); Ok(MoveOp { - src: iter.next().ok_or_else(|| CdiffError::NoMoreData("src"))?, - dst: iter.next().ok_or_else(|| CdiffError::NoMoreData("dst"))?, + src: iter.next().ok_or(CdiffError::NoMoreData("src"))?, + dst: iter.next().ok_or(CdiffError::NoMoreData("dst"))?, start_line_no: iter .next() - .ok_or_else(|| CdiffError::NoMoreData("start_line_no"))? + .ok_or(CdiffError::NoMoreData("start_line_no"))? .parse::()?, - start_line: iter - .next() - .ok_or_else(|| CdiffError::NoMoreData("start_line"))?, + start_line: iter.next().ok_or(CdiffError::NoMoreData("start_line"))?, end_line_no: iter .next() - .ok_or_else(|| CdiffError::NoMoreData("end_line_no"))? + .ok_or(CdiffError::NoMoreData("end_line_no"))? .parse::()?, - end_line: iter - .next() - .ok_or_else(|| CdiffError::NoMoreData("end_line"))?, + end_line: iter.next().ok_or(CdiffError::NoMoreData("end_line"))?, }) } } @@ -245,14 +239,10 @@ impl<'a> XchgOp<'a> { Ok(XchgOp { line_no: iter .next() - .ok_or_else(|| CdiffError::NoMoreData("line_no"))? + .ok_or(CdiffError::NoMoreData("line_no"))? .parse::()?, - orig_line: iter - .next() - .ok_or_else(|| CdiffError::NoMoreData("orig_line"))?, - new_line: iter - .next() - .ok_or_else(|| CdiffError::NoMoreData("new_line"))?, + orig_line: iter.next().ok_or(CdiffError::NoMoreData("orig_line"))?, + new_line: iter.next().ok_or(CdiffError::NoMoreData("new_line"))?, }) } } @@ -555,7 +545,7 @@ fn cmd_open(ctx: &mut Context, db_name: std::string::String) -> Result<(), Cdiff /// Set up Context structure with data parsed from command add fn cmd_add(ctx: &mut Context, signature: std::string::String) -> Result<(), CdiffError> { // Test for add without an open db - if !ctx.open_db.is_some() { + if ctx.open_db.is_none() { return Err(CdiffError::NoDBForAction("ADD")); } ctx.additions.push(signature); @@ -566,7 +556,7 @@ fn cmd_add(ctx: &mut Context, signature: std::string::String) -> Result<(), Cdif /// Set up Context structure with data parsed from command delete fn cmd_del(ctx: &mut Context, del_op: DelOp) -> Result<(), CdiffError> { // Test for add without an open db - if !ctx.open_db.is_some() { + if ctx.open_db.is_none() { return Err(CdiffError::NoDBForAction("DEL")); } @@ -584,7 +574,7 @@ fn cmd_del(ctx: &mut Context, del_op: DelOp) -> Result<(), CdiffError> { /// Set up Context structure with data parsed from command exchange fn cmd_xchg(ctx: &mut Context, xchg_op: XchgOp) -> Result<(), CdiffError> { // Test for add without an open db - if !ctx.open_db.is_some() { + if ctx.open_db.is_none() { return Err(CdiffError::NoDBForAction("XCHG")); } @@ -690,7 +680,7 @@ fn cmd_close(ctx: &mut Context) -> Result<(), CdiffError> { let open_db = ctx .open_db .take() - .ok_or_else(|| CdiffError::NoDBForAction("CLOSE"))?; + .ok_or(CdiffError::NoDBForAction("CLOSE"))?; let mut edits = ctx.edits.iter_mut(); let mut next_edit = edits.next(); diff --git a/libclamav_rust/src/logging.rs b/libclamav_rust/src/logging.rs index ca6835e911..13a09cca2b 100644 --- a/libclamav_rust/src/logging.rs +++ b/libclamav_rust/src/logging.rs @@ -74,7 +74,7 @@ mod tests { #[test] fn parse_move_works() { let init_status = clrs_log_init(); - assert!(init_status == true); + assert!(init_status); debug!("Hello"); info!("darkness"); warn!("my old");