Skip to content

Commit

Permalink
Address clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shutton committed Jan 11, 2022
1 parent 0872cc2 commit be7d505
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
8 changes: 4 additions & 4 deletions libclamav_rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> Result<(), &'static str> {

// We only want to execute cbindgen for `cargo build`, not `cargo test`.
// FindRust.cmake defines $CARGO_CMD so we can differentiate.
if "build" == env::var("CARGO_CMD").or(Ok("".to_string()))? {
if "build" == env::var("CARGO_CMD").or_else(|_| Ok("".to_string()))? {
execute_cbindgen()?;
} else {
eprintln!("NOTE: Not performing cbindgen as CARGO_CMD != build");
Expand All @@ -68,7 +68,7 @@ fn main() -> Result<(), &'static str> {

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
Expand Down Expand Up @@ -142,7 +142,7 @@ fn search_and_link_lib(environment_variable: &str) -> Result<bool, &'static str>
eprintln!(" - requesting that rustc link {:?}", &parsed_path.libname);
println!("cargo:rustc-link-lib={}", parsed_path.libname);

return Ok(true);
Ok(true)
}

struct ParsedLibraryPath {
Expand All @@ -163,7 +163,7 @@ fn parse_lib_path<'a>(path: &'a str) -> Result<ParsedLibraryPath, &'static str>
// 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();
Expand Down
40 changes: 15 additions & 25 deletions libclamav_rust/src/cdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,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::<usize>()?,
del_line: iter
.next()
.ok_or_else(|| CdiffError::NoMoreData("del_line"))?,
del_line: iter.next().ok_or(CdiffError::NoMoreData("del_line"))?,
})
}
}
Expand All @@ -208,22 +206,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::<usize>()?,
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::<usize>()?,
end_line: iter
.next()
.ok_or_else(|| CdiffError::NoMoreData("end_line"))?,
end_line: iter.next().ok_or(CdiffError::NoMoreData("end_line"))?,
})
}
}
Expand All @@ -243,14 +237,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::<usize>()?,
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"))?,
})
}
}
Expand Down Expand Up @@ -572,7 +562,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);
Expand All @@ -583,7 +573,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"));
}

Expand All @@ -601,7 +591,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"));
}

Expand Down Expand Up @@ -707,7 +697,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();
Expand Down
10 changes: 5 additions & 5 deletions libclamav_rust/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use std::os::raw::c_char;
use log::{set_max_level, Level, LevelFilter, Metadata, Record};

extern "C" {
fn cli_warnmsg(str: *const c_char, ...) -> ();
fn cli_dbgmsg(str: *const c_char, ...) -> ();
fn cli_infomsg_simple(str: *const c_char, ...) -> ();
fn cli_errmsg(str: *const c_char, ...) -> ();
fn cli_warnmsg(str: *const c_char, ...);
fn cli_dbgmsg(str: *const c_char, ...);
fn cli_infomsg_simple(str: *const c_char, ...);
fn cli_errmsg(str: *const c_char, ...);
}

pub struct ClamLogger;
Expand Down Expand Up @@ -80,7 +80,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");
Expand Down

0 comments on commit be7d505

Please sign in to comment.