Repository: gfx-rs/wgpu (language: rust)

Issue:
`RequestDeviceError: Send` inconsistency with webgpu feature
**Description**

On wasm, without feature `fragile-send-sync-non-atomic-wasm`:

If the `webgpu` feature is **not** enabled, then `RequestDeviceError: Send`, but if the `webgpu` feature is enabled, then `RequestDeviceError: !Send`. This means that the `webgpu` feature is non-additive, which is a bug.

`RequestDeviceError` should either be never `Send` or always `Send`; I think that for usability, always `Send` (by recording the JS error as text rather than a `JsValue`) would be preferable. But never `Send` would be easy to implement, by making the `WebGpu` variant not conditional on features but only on platform.

(This was introduced in commit 7774f310218bd688e27e7688f3ddf8cd39226c96 by making WebGPU its own feature, rather than something _disabled_ by a feature, but arguably my own 40cc2ee88a5c9bf281395547375e279ca30aedc0 set up the problem.)

**Platform**
wgpu 0.19.1, wasm32-unknown-unknown



Discussion / hints:
Is this still a problem on trunk? 
It must be, because `RequestDeviceErrorKind` is still conditionally containing a `JsValue` object:

https://github.com/gfx-rs/wgpu/blob/426882403dd0a67eacdaf7cca1720f860f03bbb0/wgpu/src/api/device.rs#L523-L534

Fix patch:
diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs
index f923ab4ee5..94ee333fcb 100644
--- a/wgpu/src/api/device.rs
+++ b/wgpu/src/api/device.rs
@@ -530,15 +530,9 @@ pub(crate) enum RequestDeviceErrorKind {
     ///
     /// (This is currently never used by the webgl backend, but it could be.)
     #[cfg(webgpu)]
-    WebGpu(wasm_bindgen::JsValue),
+    WebGpu(String),
 }
 
-#[cfg(send_sync)]
-unsafe impl Send for RequestDeviceErrorKind {}
-#[cfg(send_sync)]
-unsafe impl Sync for RequestDeviceErrorKind {}
-
-#[cfg(send_sync)]
 static_assertions::assert_impl_all!(RequestDeviceError: Send, Sync);
 
 impl fmt::Display for RequestDeviceError {
@@ -547,9 +541,8 @@ impl fmt::Display for RequestDeviceError {
             #[cfg(wgpu_core)]
             RequestDeviceErrorKind::Core(error) => error.fmt(_f),
             #[cfg(webgpu)]
-            RequestDeviceErrorKind::WebGpu(error_js_value) => {
-                // wasm-bindgen provides a reasonable error stringification via `Debug` impl
-                write!(_f, "{error_js_value:?}")
+            RequestDeviceErrorKind::WebGpu(error) => {
+                write!(_f, "{error}")
             }
             #[cfg(not(any(webgpu, wgpu_core)))]
             _ => unimplemented!("unknown `RequestDeviceErrorKind`"),
diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs
index adc05210f8..deaf45dee7 100644
--- a/wgpu/src/backend/webgpu.rs
+++ b/wgpu/src/backend/webgpu.rs
@@ -927,7 +927,8 @@ fn future_request_device(
             )
         })
         .map_err(|error_value| crate::RequestDeviceError {
-            inner: crate::RequestDeviceErrorKind::WebGpu(error_value),
+            // wasm-bindgen provides a reasonable error stringification via `Debug` impl
+            inner: crate::RequestDeviceErrorKind::WebGpu(format!("{error_value:?}")),
         })
 }
 


Test patch: