Skip to content

Commit

Permalink
Remove 'de: 'static" serde bound and replace &'static str with `C…
Browse files Browse the repository at this point in the history
…ow` in some errors (#6048)

* Remove `serde(bound(deserialize = "'de: 'static"))` and replace `&'static str` with `Cow` in deser errors

Signed-off-by: sagudev <[email protected]>

* Allow `clippy::result_large_err`

Signed-off-by: sagudev <[email protected]>

---------

Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev authored Jul 29, 2024
1 parent 55ae943 commit 7462754
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions wgpu-core/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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))?;
Expand Down
2 changes: 0 additions & 2 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ fn map_buffer<A: HalApi>(

#[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,
Expand All @@ -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.")]
Expand Down
7 changes: 3 additions & 4 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::{borrow::Cow, collections::HashMap};

use crate::{
api_log,
Expand All @@ -26,7 +26,7 @@ type HalSurface<A> = <A as hal::Api>::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,
}
Expand All @@ -36,7 +36,7 @@ fn check_limits(requested: &wgt::Limits, allowed: &wgt::Limits) -> Vec<FailedLim

requested.check_limits_with_fail_fn(allowed, false, |name, requested, allowed| {
failed.push(FailedLimit {
name,
name: Cow::Borrowed(name),
requested,
allowed,
})
Expand Down Expand Up @@ -389,7 +389,6 @@ pub enum GetSurfaceSupportError {

#[derive(Clone, Debug, Error)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'static")))]
/// Error when requesting a device from the adaptor
#[non_exhaustive]
pub enum RequestDeviceError {
Expand Down
9 changes: 3 additions & 6 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use smallvec::SmallVec;
use thiserror::Error;

use std::{
borrow::Borrow,
borrow::{Borrow, Cow},
fmt::Debug,
iter,
mem::{self, ManuallyDrop},
Expand Down Expand Up @@ -78,7 +78,7 @@ impl TrackingData {
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResourceErrorIdent {
r#type: &'static str,
r#type: Cow<'static, str>,
label: String,
}

Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down

0 comments on commit 7462754

Please sign in to comment.