From ac6fe3e31cdc64492d3f27a160ca796ae12563af Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 10 Jun 2024 15:01:12 -0700 Subject: [PATCH] Avoid clippy::blocks_in_conditions warnings Assign the result of function calls that take closures to an intermediate variable rather than matching on it directly to simplify the complexity from clippy's point of view. BUG=b:344974550 TEST=tools/clippy Change-Id: I0e4b4201b59d8bd972c1f18e65bfd501893d58e5 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5617618 Commit-Queue: Daniel Verkamp Reviewed-by: Frederick Mayle --- base_tokio/src/sys/linux/event.rs | 6 ++++-- base_tokio/src/sys/linux/tube.rs | 12 ++++++++---- e2e_tests/fixture/src/sys/linux.rs | 6 ++++-- fuse/src/server.rs | 6 ++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/base_tokio/src/sys/linux/event.rs b/base_tokio/src/sys/linux/event.rs index 6960e767ae..016b99eb60 100644 --- a/base_tokio/src/sys/linux/event.rs +++ b/base_tokio/src/sys/linux/event.rs @@ -24,7 +24,7 @@ impl EventTokio { pub async fn wait(&self) -> std::io::Result<()> { loop { let mut guard = self.0.readable().await?; - match guard.try_io(|inner| { + let io_result = guard.try_io(|inner| { let mut buf: u64 = 0; // SAFETY: This is safe because we made this fd and the pointer we pass can not // overflow because we give the syscall's size parameter properly. @@ -42,7 +42,9 @@ impl EventTokio { return Err(std::io::Error::from(std::io::ErrorKind::UnexpectedEof)); } Ok(()) - }) { + }); + + match io_result { Ok(result) => return result, Err(_would_block) => continue, } diff --git a/base_tokio/src/sys/linux/tube.rs b/base_tokio/src/sys/linux/tube.rs index 5e40d39e34..49b7ff0772 100644 --- a/base_tokio/src/sys/linux/tube.rs +++ b/base_tokio/src/sys/linux/tube.rs @@ -28,7 +28,7 @@ impl TubeTokio { ) -> base::TubeResult<()> { loop { let mut guard = self.0.writable().await.map_err(base::TubeError::Send)?; - match guard.try_io(|inner| { + let io_result = guard.try_io(|inner| { // Re-using the non-async send is potentially hazardous since it isn't explicitly // written with O_NONBLOCK support. However, since it uses SOCK_SEQPACKET and a // single write syscall, it should be OK. @@ -40,7 +40,9 @@ impl TubeTokio { Err(base::TubeError::Send(e)) => Err(e), Err(e) => Ok(Err(e)), } - }) { + }); + + match io_result { Ok(result) => { return match result { Ok(Ok(x)) => Ok(x), @@ -58,7 +60,7 @@ impl TubeTokio { ) -> base::TubeResult { loop { let mut guard = self.0.readable().await.map_err(base::TubeError::Recv)?; - match guard.try_io(|inner| { + let io_result = guard.try_io(|inner| { // Re-using the non-async recv is potentially hazardous since it isn't explicitly // written with O_NONBLOCK support. However, since it uses SOCK_SEQPACKET and a // single read syscall, it should be OK. @@ -70,7 +72,9 @@ impl TubeTokio { Err(base::TubeError::Recv(e)) => Err(e), Err(e) => Ok(Err(e)), } - }) { + }); + + match io_result { Ok(result) => { return match result { Ok(Ok(x)) => Ok(x), diff --git a/e2e_tests/fixture/src/sys/linux.rs b/e2e_tests/fixture/src/sys/linux.rs index 9bba2b996f..caab43fc0a 100644 --- a/e2e_tests/fixture/src/sys/linux.rs +++ b/e2e_tests/fixture/src/sys/linux.rs @@ -189,7 +189,7 @@ impl TestVmSys { // Open pipes. Apply timeout to `to_guest` and `from_guest` since it will block until crosvm // opens the other end. let start = Instant::now(); - let (to_guest, from_guest) = match run_with_status_check( + let run_result = run_with_status_check( move || (File::create(to_guest_pipe), File::open(from_guest_pipe)), Duration::from_millis(200), || { @@ -203,7 +203,9 @@ impl TestVmSys { true } }, - ) { + ); + + let (to_guest, from_guest) = match run_result { Ok((to_guest, from_guest)) => ( to_guest.context("Cannot open to_guest pipe")?, from_guest.context("Cannot open from_guest pipe")?, diff --git a/fuse/src/server.rs b/fuse/src/server.rs index 3b988bf55b..63f11397f3 100644 --- a/fuse/src/server.rs +++ b/fuse/src/server.rs @@ -1206,13 +1206,15 @@ impl Server { let mut total_written = 0; while let Some(dirent) = entries.next() { let mut entry_inode = None; - match self + let dirent_result = self .lookup_dirent_attribute(&in_header, &dirent) .and_then(|e| { entry_inode = Some(e.inode); let remaining = (size as usize).saturating_sub(total_written); add_dirent(cursor, remaining, &dirent, Some(e)) - }) { + }); + + match dirent_result { Ok(0) => { // No more space left in the buffer but we need to undo the lookup // that created the Entry or we will end up with mismatched lookup