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 <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
This commit is contained in:
Daniel Verkamp 2024-06-10 15:01:12 -07:00 committed by crosvm LUCI
parent 2dfbd8458c
commit ac6fe3e31c
4 changed files with 20 additions and 10 deletions

View file

@ -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,
}

View file

@ -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<T> {
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),

View file

@ -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")?,

View file

@ -1206,13 +1206,15 @@ impl<F: FileSystem + Sync> Server<F> {
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