From e88ec058e433305c0496a8dae3b280eed934c0ec Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:02:43 +0200 Subject: [PATCH 1/2] Remove `serde(bound(deserialize = "'de: 'static"))` and replace `&'static str` with `Cow` in deser errors Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu-core/src/device/mod.rs | 2 -- wgpu-core/src/instance.rs | 7 +++---- wgpu-core/src/resource.rs | 9 +++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 222c50248a..d33de22dac 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -365,7 +365,6 @@ fn map_buffer( #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))] pub struct DeviceMismatch { pub(super) res: ResourceErrorIdent, pub(super) res_device: ResourceErrorIdent, @@ -391,7 +390,6 @@ impl std::error::Error for DeviceMismatch {} #[derive(Clone, Debug, Error)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))] #[non_exhaustive] pub enum DeviceError { #[error("{0} is invalid.")] diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 65bed375f1..c4433ed148 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -1,5 +1,5 @@ -use std::collections::HashMap; use std::sync::Arc; +use std::{borrow::Cow, collections::HashMap}; use crate::{ api_log, @@ -26,7 +26,7 @@ type HalSurface = ::Surface; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[error("Limit '{name}' value {requested} is better than allowed {allowed}")] pub struct FailedLimit { - name: &'static str, + name: Cow<'static, str>, requested: u64, allowed: u64, } @@ -36,7 +36,7 @@ fn check_limits(requested: &wgt::Limits, allowed: &wgt::Limits) -> Vec, label: String, } @@ -156,7 +156,7 @@ pub(crate) trait Labeled: ResourceType { fn error_ident(&self) -> ResourceErrorIdent { ResourceErrorIdent { - r#type: Self::TYPE, + r#type: Cow::Borrowed(Self::TYPE), label: self.label().to_owned(), } } @@ -343,7 +343,6 @@ pub struct BufferMapOperation { #[derive(Clone, Debug, Error)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))] #[non_exhaustive] pub enum BufferAccessError { #[error(transparent)] @@ -393,7 +392,6 @@ pub enum BufferAccessError { #[derive(Clone, Debug, Error)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))] #[error("Usage flags {actual:?} of {res} do not contain required usage flags {expected:?}")] pub struct MissingBufferUsageError { pub(crate) res: ResourceErrorIdent, @@ -411,7 +409,6 @@ pub struct MissingTextureUsageError { #[derive(Clone, Debug, Error)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))] #[error("{0} has been destroyed")] pub struct DestroyedResourceError(pub ResourceErrorIdent); From 4fa8f27baab74f770e21834232c579f6b6421e3f Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:12:34 +0200 Subject: [PATCH 2/2] Allow `clippy::result_large_err` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu-core/src/command/bind.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/wgpu-core/src/command/bind.rs b/wgpu-core/src/command/bind.rs index 73f1d9fe17..f1dacee923 100644 --- a/wgpu-core/src/command/bind.rs +++ b/wgpu-core/src/command/bind.rs @@ -254,6 +254,7 @@ mod compat { .filter_map(|(i, e)| if e.is_active() { Some(i) } else { None }) } + #[allow(clippy::result_large_err)] pub fn get_invalid(&self) -> Result<(), (usize, Error)> { for (index, entry) in self.entries.iter().enumerate() { entry.check().map_err(|e| (index, e))?;