From ee15fbbbc5cb918e0ba7fbcc74b4d22ce8fac6d6 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Tue, 19 Jul 2022 16:48:33 +0200 Subject: [PATCH] bpf: Use `then_some` instead of `then(|| [...])` This change fixes the `unnecessary_lazy_evaluations` clippy warning. Signed-off-by: Michal Rostecki --- bpf/aya-bpf/src/maps/bloom_filter.rs | 4 ++-- bpf/aya-bpf/src/maps/hash_map.rs | 4 ++-- bpf/aya-bpf/src/maps/lpm_trie.rs | 4 ++-- bpf/aya-bpf/src/maps/queue.rs | 4 ++-- bpf/aya-bpf/src/maps/sock_hash.rs | 4 ++-- bpf/aya-bpf/src/maps/sock_map.rs | 2 +- bpf/aya-bpf/src/maps/stack.rs | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bpf/aya-bpf/src/maps/bloom_filter.rs b/bpf/aya-bpf/src/maps/bloom_filter.rs index 25a1e749..d15d264f 100644 --- a/bpf/aya-bpf/src/maps/bloom_filter.rs +++ b/bpf/aya-bpf/src/maps/bloom_filter.rs @@ -47,7 +47,7 @@ impl BloomFilter { value as *const _ as *mut c_void, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } #[inline] @@ -59,7 +59,7 @@ impl BloomFilter { flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } } diff --git a/bpf/aya-bpf/src/maps/hash_map.rs b/bpf/aya-bpf/src/maps/hash_map.rs index 175cb147..5877be90 100644 --- a/bpf/aya-bpf/src/maps/hash_map.rs +++ b/bpf/aya-bpf/src/maps/hash_map.rs @@ -348,11 +348,11 @@ fn insert(def: *mut bpf_map_def, key: &K, value: &V, flags: u64) -> Result flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } #[inline] fn remove(def: *mut bpf_map_def, key: &K) -> Result<(), c_long> { let ret = unsafe { bpf_map_delete_elem(def as *mut _, key as *const _ as *const c_void) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } diff --git a/bpf/aya-bpf/src/maps/lpm_trie.rs b/bpf/aya-bpf/src/maps/lpm_trie.rs index fc40e506..ff78003f 100644 --- a/bpf/aya-bpf/src/maps/lpm_trie.rs +++ b/bpf/aya-bpf/src/maps/lpm_trie.rs @@ -78,7 +78,7 @@ impl LpmTrie { flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } #[inline] @@ -86,7 +86,7 @@ impl LpmTrie { let ret = unsafe { bpf_map_delete_elem(self.def.get() as *mut _, key as *const _ as *const c_void) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } } diff --git a/bpf/aya-bpf/src/maps/queue.rs b/bpf/aya-bpf/src/maps/queue.rs index bb6b29c0..8c8f0bb1 100644 --- a/bpf/aya-bpf/src/maps/queue.rs +++ b/bpf/aya-bpf/src/maps/queue.rs @@ -53,14 +53,14 @@ impl Queue { flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } pub fn pop(&self) -> Option { unsafe { let mut value = mem::MaybeUninit::uninit(); let ret = bpf_map_pop_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _); - (ret == 0).then(|| value.assume_init()) + (ret == 0).then_some(value.assume_init()) } } } diff --git a/bpf/aya-bpf/src/maps/sock_hash.rs b/bpf/aya-bpf/src/maps/sock_hash.rs index 0bbb5f39..a43fcc81 100644 --- a/bpf/aya-bpf/src/maps/sock_hash.rs +++ b/bpf/aya-bpf/src/maps/sock_hash.rs @@ -61,7 +61,7 @@ impl SockHash { flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } pub fn redirect_msg(&self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 { @@ -102,7 +102,7 @@ impl SockHash { } let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); bpf_sk_release(sk); - (ret == 0).then(|| ()).ok_or(1) + (ret == 0).then_some(()).ok_or(1) } } } diff --git a/bpf/aya-bpf/src/maps/sock_map.rs b/bpf/aya-bpf/src/maps/sock_map.rs index 9f9a1636..80c6fe7e 100644 --- a/bpf/aya-bpf/src/maps/sock_map.rs +++ b/bpf/aya-bpf/src/maps/sock_map.rs @@ -102,7 +102,7 @@ impl SockMap { } let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); bpf_sk_release(sk); - (ret == 0).then(|| ()).ok_or(1) + (ret == 0).then_some(()).ok_or(1) } } } diff --git a/bpf/aya-bpf/src/maps/stack.rs b/bpf/aya-bpf/src/maps/stack.rs index d78df353..6328693d 100644 --- a/bpf/aya-bpf/src/maps/stack.rs +++ b/bpf/aya-bpf/src/maps/stack.rs @@ -51,7 +51,7 @@ impl Stack { flags, ) }; - (ret == 0).then(|| ()).ok_or(ret) + (ret == 0).then_some(()).ok_or(ret) } pub fn pop(&mut self) -> Option { @@ -61,7 +61,7 @@ impl Stack { &mut self.def as *mut _ as *mut _, value.as_mut_ptr() as *mut _, ); - (ret == 0).then(|| value.assume_init()) + (ret == 0).then_some(value.assume_init()) } } }