From 9bd9c0cb719cb3e54088b978b4bebff31b13785f Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Thu, 12 Jun 2025 16:44:11 +0200 Subject: [PATCH] misc: replace manual `From` for `*Error` with `#[from]` This is a small simplification we can use since we use `thiserror` anyway. Note that `#[from]` implies `#[source]` [0]. [0]: https://docs.rs/thiserror/2.0.12/thiserror/index.html Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- arch/src/aarch64/mod.rs | 6 ------ arch/src/lib.rs | 6 +++--- arch/src/riscv64/mod.rs | 6 ------ arch/src/x86_64/mod.rs | 6 ------ performance-metrics/src/performance_tests.rs | 8 +------- test_infra/src/lib.rs | 8 +------- vmm/src/api/http/mod.rs | 8 +------- 7 files changed, 6 insertions(+), 42 deletions(-) diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index d0a6eb002..3c7010e63 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -56,12 +56,6 @@ pub enum Error { VcpuInitPmu, } -impl From for super::Error { - fn from(e: Error) -> super::Error { - super::Error::PlatformSpecific(e) - } -} - #[derive(Debug, Copy, Clone)] /// Specifies the entry point address where the guest must start /// executing code. diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 38d258859..477c5b01e 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -29,13 +29,13 @@ type GuestRegionMmap = vm_memory::GuestRegionMmap for super::Error { - fn from(e: Error) -> super::Error { - super::Error::PlatformSpecific(e) - } -} - #[derive(Debug, Copy, Clone)] /// Specifies the entry point address where the guest must start /// executing code. diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index d6723330e..e91c23be1 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -209,12 +209,6 @@ pub enum Error { E820Configuration, } -impl From for super::Error { - fn from(e: Error) -> super::Error { - super::Error::PlatformSpecific(e) - } -} - pub fn get_x2apic_id(cpu_id: u32, topology: Option<(u8, u8, u8)>) -> u32 { if let Some(t) = topology { let thread_mask_width = u8::BITS - (t.0 - 1).leading_zeros(); diff --git a/performance-metrics/src/performance_tests.rs b/performance-metrics/src/performance_tests.rs index f398d7977..7cab1db1b 100644 --- a/performance-metrics/src/performance_tests.rs +++ b/performance-metrics/src/performance_tests.rs @@ -25,17 +25,11 @@ enum Error { #[error("boot time could not be parsed")] BootTimeParse, #[error("infrastructure failure: {0}")] - Infra(#[source] InfraError), + Infra(#[from] InfraError), #[error("restore time could not be parsed")] RestoreTimeParse, } -impl From for Error { - fn from(e: InfraError) -> Self { - Self::Infra(e) - } -} - const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img"; pub fn init_tests() { diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index b61a57132..c624c1e2a 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -40,7 +40,7 @@ pub enum Error { #[error("Failed to parse: {0}")] Parsing(#[source] std::num::ParseIntError), #[error("ssh command failed: {0}")] - SshCommand(#[source] SshCommandError), + SshCommand(#[from] SshCommandError), #[error("waiting for boot failed: {0}")] WaitForBoot(#[source] WaitForBootError), #[error("reading log file failed: {0}")] @@ -57,12 +57,6 @@ pub enum Error { WaitTimeout(#[source] WaitTimeoutError), } -impl From for Error { - fn from(e: SshCommandError) -> Self { - Self::SshCommand(e) - } -} - pub struct GuestNetworkConfig { pub guest_ip: String, pub l2_guest_ip1: String, diff --git a/vmm/src/api/http/mod.rs b/vmm/src/api/http/mod.rs index 228cef296..49df05a96 100644 --- a/vmm/src/api/http/mod.rs +++ b/vmm/src/api/http/mod.rs @@ -44,7 +44,7 @@ pub type HttpApiHandle = (thread::JoinHandle>, EventFd); pub enum HttpError { /// API request receive error #[error("Failed to deserialize JSON: {0}")] - SerdeJsonDeserialize(#[source] SerdeError), + SerdeJsonDeserialize(#[from] SerdeError), /// Attempt to access unsupported HTTP method #[error("Bad Request")] @@ -67,12 +67,6 @@ pub enum HttpError { ApiError(#[source] ApiError), } -impl From for HttpError { - fn from(e: serde_json::Error) -> Self { - HttpError::SerdeJsonDeserialize(e) - } -} - const HTTP_ROOT: &str = "/api/v1"; pub fn error_response(error: HttpError, status: StatusCode) -> Response {