Simplify some pattern-matches (#16402) (#16446)

When those match an exact combinator on Option / Result.

Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust).

(cherry picked from commit b08cff9e77)

Co-authored-by: François Garillot <4142+huitseeker@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-04-08 20:45:01 +00:00
committed by GitHub
parent f7211d3c07
commit 723e7f11b9
18 changed files with 60 additions and 110 deletions

View File

@@ -297,10 +297,8 @@ fn translate_type_inner<'a, T>(
Err(SyscallError::UnalignedPointer.into())
} else {
unsafe {
match translate(memory_mapping, access_type, vm_addr, size_of::<T>() as u64) {
Ok(value) => Ok(&mut *(value as *mut T)),
Err(e) => Err(e),
}
translate(memory_mapping, access_type, vm_addr, size_of::<T>() as u64)
.map(|value| &mut *(value as *mut T))
}
}
}
@@ -316,10 +314,8 @@ fn translate_type<'a, T>(
vm_addr: u64,
loader_id: &Pubkey,
) -> Result<&'a T, EbpfError<BpfError>> {
match translate_type_inner::<T>(memory_mapping, AccessType::Load, vm_addr, loader_id) {
Ok(value) => Ok(&*value),
Err(e) => Err(e),
}
translate_type_inner::<T>(memory_mapping, AccessType::Load, vm_addr, loader_id)
.map(|value| &*value)
}
fn translate_slice_inner<'a, T>(
@@ -361,10 +357,8 @@ fn translate_slice<'a, T>(
len: u64,
loader_id: &Pubkey,
) -> Result<&'a [T], EbpfError<BpfError>> {
match translate_slice_inner::<T>(memory_mapping, AccessType::Load, vm_addr, len, loader_id) {
Ok(value) => Ok(&*value),
Err(e) => Err(e),
}
translate_slice_inner::<T>(memory_mapping, AccessType::Load, vm_addr, len, loader_id)
.map(|value| &*value)
}
/// Take a virtual pointer to a string (points to BPF VM memory space), translate it