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 18, 2022
1 parent 428cd79 commit 35269d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
6 changes: 3 additions & 3 deletions libclamav_rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -234,7 +234,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 @@ -255,7 +255,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 @@ -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::<usize>()?,
del_line: iter
.next()
.ok_or_else(|| CdiffError::NoMoreData("del_line"))?,
del_line: iter.next().ok_or(CdiffError::NoMoreData("del_line"))?,
})
}
}
Expand All @@ -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::<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 @@ -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::<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 @@ -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);
Expand All @@ -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"));
}

Expand All @@ -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"));
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion libclamav_rust/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 35269d3

Please sign in to comment.