From 24f779696b68841c73e4eedfb4ebd7bdf208a255 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Tue, 10 Jun 2025 10:26:36 -0700 Subject: [PATCH] Tweak MapPassErr to work for both errors and results (#7780) --- wgpu-core/src/command/bundle.rs | 10 +++++----- wgpu-core/src/command/compute.rs | 10 +++++----- wgpu-core/src/command/mod.rs | 13 +++++++++++-- wgpu-core/src/command/render.rs | 13 +++++-------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index d1d848f08..486246de2 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -1519,15 +1519,15 @@ impl RenderBundleError { } } -impl MapPassErr for Result +impl MapPassErr for E where E: Into, { - fn map_pass_err(self, scope: PassErrorScope) -> Result { - self.map_err(|inner| RenderBundleError { + fn map_pass_err(self, scope: PassErrorScope) -> RenderBundleError { + RenderBundleError { scope, - inner: inner.into(), - }) + inner: self.into(), + } } } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index f25fbe520..80350504b 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -182,15 +182,15 @@ pub struct ComputePassError { pub(super) inner: ComputePassErrorInner, } -impl MapPassErr for Result +impl MapPassErr for E where E: Into, { - fn map_pass_err(self, scope: PassErrorScope) -> Result { - self.map_err(|inner| ComputePassError { + fn map_pass_err(self, scope: PassErrorScope) -> ComputePassError { + ComputePassError { scope, - inner: inner.into(), - }) + inner: self.into(), + } } } diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index c7f5b3b9f..b8c4022fc 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -1029,8 +1029,17 @@ impl Default for BindGroupStateChange { } } -trait MapPassErr { - fn map_pass_err(self, scope: PassErrorScope) -> Result; +trait MapPassErr { + fn map_pass_err(self, scope: PassErrorScope) -> T; +} + +impl MapPassErr> for Result +where + E: MapPassErr, +{ + fn map_pass_err(self, scope: PassErrorScope) -> Result { + self.map_err(|err| err.map_pass_err(scope)) + } } #[derive(Clone, Copy, Debug)] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 7df559fa9..89032fdf4 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -807,15 +807,12 @@ pub struct RenderPassError { pub(super) inner: RenderPassErrorInner, } -impl MapPassErr for Result -where - E: Into, -{ - fn map_pass_err(self, scope: PassErrorScope) -> Result { - self.map_err(|inner| RenderPassError { +impl> MapPassErr for E { + fn map_pass_err(self, scope: PassErrorScope) -> RenderPassError { + RenderPassError { scope, - inner: inner.into(), - }) + inner: self.into(), + } } }