From d4417f210e1ec2a702841af339e048f16d6af683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 24 Jun 2022 11:17:33 +0200 Subject: [PATCH] netlink: Fix "or-fun-call" clippy warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error shown below was caught during a dependency bump in the CCv0 branch, but we better fix it here first. ``` error: use of `ok_or` followed by a function call --> src/netlink.rs:526:14 | 526 | .ok_or(anyhow!(nix::Error::EINVAL))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `ok_or_else(|| anyhow!(nix::Error::EINVAL))` | = note: `-D clippy::or-fun-call` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call error: use of `ok_or` followed by a function call --> src/netlink.rs:615:49 | 615 | let v = u8::from_str_radix(split.next().ok_or(anyhow!(nix::Error::EINVAL))?, 16)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `ok_or_else(|| anyhow!(nix::Error::EINVAL))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call ``` Fixes: #4523 Signed-off-by: Fabiano FidĂȘncio --- src/agent/src/netlink.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index ed071b60a4..1de4ef6920 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -523,7 +523,7 @@ impl Handle { .as_ref() .map(|to| to.address.as_str()) // Extract address field .and_then(|addr| if addr.is_empty() { None } else { Some(addr) }) // Make sure it's not empty - .ok_or(anyhow!(nix::Error::EINVAL))?; + .ok_or_else(|| anyhow!(nix::Error::EINVAL))?; let ip = IpAddr::from_str(ip_address) .map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?; @@ -612,7 +612,7 @@ fn parse_mac_address(addr: &str) -> Result<[u8; 6]> { // Parse single Mac address block let mut parse_next = || -> Result { - let v = u8::from_str_radix(split.next().ok_or(anyhow!(nix::Error::EINVAL))?, 16)?; + let v = u8::from_str_radix(split.next().ok_or_else(|| anyhow!(nix::Error::EINVAL))?, 16)?; Ok(v) };