From f4f8f86873de1663441f1cb2fbea92df2fbfa31d Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 16 Jul 2020 11:26:32 -0700 Subject: [PATCH] Fix new clippy warnings from Rust 1.45.0 Fix a few instances of and_then(Ok(...)) in syslog: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map And an unused (overwritten) variable assignment in the argument tests. BUG=None TEST=docker/wrapped_smoke_test.sh Change-Id: Id59b1749fd7eba1fe7dfeb7938ecbbc9d0f9aa6a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2303275 Reviewed-by: Keiichi Watanabe Commit-Queue: Daniel Verkamp Tested-by: kokoro --- src/argument.rs | 26 ++++++++++---------------- sys_util/src/syslog.rs | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/argument.rs b/src/argument.rs index 02e97f0b5a..abe94c2902 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -505,23 +505,17 @@ mod tests { "foo" => assert!(value.is_none()), "bar" => assert_eq!(value.unwrap(), "stuff"), "gpu" => match value { - Some(v) => { - match v { - "2D" => { - gpu_value = Some("2D".to_string()); - } - "3D" => { - gpu_value = Some("3D".to_string()); - } - _ => { - return Err(Error::InvalidValue { - value: v.to_string(), - expected: String::from("2D or 3D"), - }) - } + Some(v) => match v { + "2D" | "3D" => { + gpu_value = Some(v.to_string()); } - gpu_value = Some(v.to_string()); - } + _ => { + return Err(Error::InvalidValue { + value: v.to_string(), + expected: String::from("2D or 3D"), + }) + } + }, None => { gpu_value = None; } diff --git a/sys_util/src/syslog.rs b/sys_util/src/syslog.rs index 232f046c8d..54772c252e 100644 --- a/sys_util/src/syslog.rs +++ b/sys_util/src/syslog.rs @@ -439,7 +439,7 @@ pub fn log(pri: Priority, fac: Facility, file_line: Option<(&str, u32)>, args: f } }) .and_then(|()| write!(&mut buf_cursor, "{}", args)) - .and_then(|()| Ok(buf_cursor.position() as usize)) + .map(|()| buf_cursor.position() as usize) }; if let Ok(len) = &res { @@ -455,7 +455,7 @@ pub fn log(pri: Priority, fac: Facility, file_line: Option<(&str, u32)>, args: f Ok(()) } .and_then(|()| writeln!(&mut buf_cursor, "{}", args)) - .and_then(|()| Ok(buf_cursor.position() as usize)) + .map(|()| buf_cursor.position() as usize) }; if let Ok(len) = &res { if let Some(file) = &mut state.file {